TASK: Code style

This commit is contained in:
Torsten Blindert 2018-10-02 09:09:12 +02:00
parent 0262f59a3f
commit a3d050ff6b
6 changed files with 21 additions and 20 deletions

View File

@ -1476,7 +1476,7 @@ class Parser
$start = $this->lexer->token; $start = $this->lexer->token;
$this->expectKeyword('extend'); $this->expectKeyword('extend');
$this->expectKeyword('schema'); $this->expectKeyword('schema');
$directives = $this->parseDirectives(true); $directives = $this->parseDirectives(true);
$operationTypes = $this->peek(Token::BRACE_L) $operationTypes = $this->peek(Token::BRACE_L)
? $this->many( ? $this->many(
Token::BRACE_L, Token::BRACE_L,
@ -1490,7 +1490,7 @@ class Parser
return new SchemaTypeExtensionNode([ return new SchemaTypeExtensionNode([
'directives' => $directives, 'directives' => $directives,
'operationTypes' => $operationTypes, 'operationTypes' => $operationTypes,
'loc' => $this->loc($start) 'loc' => $this->loc($start),
]); ]);
} }

View File

@ -341,7 +341,7 @@ class Printer
[ [
'extend schema', 'extend schema',
$this->join($def->directives, ' '), $this->join($def->directives, ' '),
$this->block($def->operationTypes) $this->block($def->operationTypes),
], ],
' ' ' '
); );

View File

@ -166,7 +166,7 @@ class Visitor
NodeKind::DIRECTIVE_DEFINITION => ['description', 'name', 'arguments', 'locations'], NodeKind::DIRECTIVE_DEFINITION => ['description', 'name', 'arguments', 'locations'],
NodeKind::SCHEMA_EXTENSION => ['directives', 'operationTypes'] NodeKind::SCHEMA_EXTENSION => ['directives', 'operationTypes'],
]; ];
/** /**

View File

@ -114,7 +114,7 @@ class Schema
); );
} }
$this->config = $config; $this->config = $config;
$this->extensionASTNodes = $config->extensionASTNodes; $this->extensionASTNodes = $config->extensionASTNodes;
if ($config->query) { if ($config->query) {

View File

@ -278,7 +278,7 @@ class SchemaConfig
/** /**
* @return SchemaTypeExtensionNode[] * @return SchemaTypeExtensionNode[]
*/ */
public function getExtensionASTNodes(): array public function getExtensionASTNodes()
{ {
return $this->extensionASTNodes; return $this->extensionASTNodes;
} }
@ -286,7 +286,7 @@ class SchemaConfig
/** /**
* @param SchemaTypeExtensionNode[] $extensionASTNodes * @param SchemaTypeExtensionNode[] $extensionASTNodes
*/ */
public function setExtensionASTNodes(array $extensionASTNodes): void public function setExtensionASTNodes(array $extensionASTNodes)
{ {
$this->extensionASTNodes = $extensionASTNodes; $this->extensionASTNodes = $extensionASTNodes;
} }

View File

@ -5,38 +5,37 @@ declare(strict_types=1);
namespace GraphQL\Validator\Rules; namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error; use GraphQL\Error\Error;
use GraphQL\Language\AST\DirectiveDefinitionNode;
use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\DirectiveNode;
use GraphQL\Language\AST\InputObjectTypeDefinitionNode; use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
use GraphQL\Language\AST\Node; use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeKind; use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\NodeList; use GraphQL\Language\AST\NodeList;
use GraphQL\Language\DirectiveLocation; use GraphQL\Language\DirectiveLocation;
use GraphQL\Type\Definition\Directive;
use GraphQL\Validator\ValidationContext; use GraphQL\Validator\ValidationContext;
use function count; use function count;
use function in_array; use function in_array;
use function sprintf; use function sprintf;
use function array_map;
class KnownDirectives extends ValidationRule class KnownDirectives extends ValidationRule
{ {
/**
* @param ValidationContext $context
* @return array
*/
public function getVisitor(ValidationContext $context) public function getVisitor(ValidationContext $context)
{ {
$locationsMap = []; $locationsMap = [];
$schema = $context->getSchema(); $schema = $context->getSchema();
$definedDirectives = $schema ? $schema->getDirectives() : Directive::getInternalDirectives(); $definedDirectives = $schema->getDirectives();
foreach ($definedDirectives as $directive) { foreach ($definedDirectives as $directive) {
$locationsMap[$directive->name] = $directive->locations; $locationsMap[$directive->name] = $directive->locations;
} }
$astDefinition = $context->getDocument()->definitions; $astDefinition = $context->getDocument()->definitions;
foreach ($astDefinition as $def) { foreach ($astDefinition as $def) {
if ($def->kind === NodeKind::DIRECTIVE_DEFINITION) { if ($def instanceof DirectiveDefinitionNode) {
$locationsMap[$def->name->value] = array_map(function ($name) { $locationsMap[$def->name->value] = array_map(function ($name) {
return $name->value; return $name->value;
}, $def->locations); }, $def->locations);
@ -47,7 +46,7 @@ class KnownDirectives extends ValidationRule
$name = $node->name->value; $name = $node->name->value;
$locations = $locationsMap[$name] ?? null; $locations = $locationsMap[$name] ?? null;
if (!$locations) { if (! $locations) {
$context->reportError(new Error( $context->reportError(new Error(
self::unknownDirectiveMessage($name), self::unknownDirectiveMessage($name),
[$node] [$node]
@ -57,11 +56,13 @@ class KnownDirectives extends ValidationRule
$candidateLocation = $this->getDirectiveLocationForASTPath($ancestors); $candidateLocation = $this->getDirectiveLocationForASTPath($ancestors);
if ($candidateLocation && !in_array($candidateLocation, $locations)) { if ($candidateLocation && ! in_array($candidateLocation, $locations)) {
$context->reportError(new Error( $context->reportError(
self::misplacedDirectiveMessage($name, $candidateLocation), new Error(
[$node] self::misplacedDirectiveMessage($name, $candidateLocation),
)); [$node]
)
);
} }
} }
]; ];