From 5a1caf05496b666469d98de2a35f7ead923fb7d3 Mon Sep 17 00:00:00 2001 From: Torsten Blindert Date: Tue, 2 Oct 2018 09:34:29 +0200 Subject: [PATCH] TASK: Code style #2 --- src/Validator/Rules/KnownDirectives.php | 36 +++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Validator/Rules/KnownDirectives.php b/src/Validator/Rules/KnownDirectives.php index fee65f6..b179829 100644 --- a/src/Validator/Rules/KnownDirectives.php +++ b/src/Validator/Rules/KnownDirectives.php @@ -13,19 +13,17 @@ use GraphQL\Language\AST\NodeKind; use GraphQL\Language\AST\NodeList; use GraphQL\Language\DirectiveLocation; use GraphQL\Validator\ValidationContext; +use function array_map; use function count; use function in_array; use function sprintf; -use function array_map; class KnownDirectives extends ValidationRule { - public function getVisitor(ValidationContext $context) { $locationsMap = []; - $schema = $context->getSchema(); - + $schema = $context->getSchema(); $definedDirectives = $schema->getDirectives(); foreach ($definedDirectives as $directive) { @@ -35,15 +33,17 @@ class KnownDirectives extends ValidationRule $astDefinition = $context->getDocument()->definitions; foreach ($astDefinition as $def) { - if ($def instanceof DirectiveDefinitionNode) { - $locationsMap[$def->name->value] = array_map(function ($name) { - return $name->value; - }, $def->locations); + if (! ($def instanceof DirectiveDefinitionNode)) { + continue; } + + $locationsMap[$def->name->value] = array_map(function ($name) { + return $name->value; + }, $def->locations); } return [ NodeKind::DIRECTIVE => function (DirectiveNode $node, $key, $parent, $path, $ancestors) use ($context, $locationsMap) { - $name = $node->name->value; + $name = $node->name->value; $locations = $locationsMap[$name] ?? null; if (! $locations) { @@ -56,15 +56,17 @@ class KnownDirectives extends ValidationRule $candidateLocation = $this->getDirectiveLocationForASTPath($ancestors); - if ($candidateLocation && ! in_array($candidateLocation, $locations)) { - $context->reportError( - new Error( - self::misplacedDirectiveMessage($name, $candidateLocation), - [$node] - ) - ); + if (! $candidateLocation || in_array($candidateLocation, $locations)) { + return; } - } + + $context->reportError( + new Error( + self::misplacedDirectiveMessage($name, $candidateLocation), + [$node] + ) + ); + }, ]; }