Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/webonyx/graphql-php/src/Validator/Rules/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/webonyx/graphql-php/src/Validator/Rules/NoUnusedVariables.php
<?php declare(strict_types=1);

namespace GraphQL\Validator\Rules;

use GraphQL\Error\Error;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\VariableDefinitionNode;
use GraphQL\Validator\QueryValidationContext;

class NoUnusedVariables extends ValidationRule
{
    /** @var array<int, VariableDefinitionNode> */
    protected array $variableDefs;

    public function getVisitor(QueryValidationContext $context): array
    {
        $this->variableDefs = [];

        return [
            NodeKind::OPERATION_DEFINITION => [
                'enter' => function (): void {
                    $this->variableDefs = [];
                },
                'leave' => function (OperationDefinitionNode $operation) use ($context): void {
                    $variableNameUsed = [];
                    $usages = $context->getRecursiveVariableUsages($operation);
                    $opName = $operation->name !== null
                        ? $operation->name->value
                        : null;

                    foreach ($usages as $usage) {
                        $node = $usage['node'];
                        $variableNameUsed[$node->name->value] = true;
                    }

                    foreach ($this->variableDefs as $variableDef) {
                        $variableName = $variableDef->variable->name->value;

                        if (! isset($variableNameUsed[$variableName])) {
                            $context->reportError(new Error(
                                static::unusedVariableMessage($variableName, $opName),
                                [$variableDef]
                            ));
                        }
                    }
                },
            ],
            NodeKind::VARIABLE_DEFINITION => function ($def): void {
                $this->variableDefs[] = $def;
            },
        ];
    }

    public static function unusedVariableMessage(string $varName, string $opName = null): string
    {
        return $opName !== null
            ? "Variable \"\${$varName}\" is never used in operation \"{$opName}\"."
            : "Variable \"\${$varName}\" is never used.";
    }
}

Spamworldpro Mini