diff --git a/src/Language/AST/EnumTypeDefinitionNode.php b/src/Language/AST/EnumTypeDefinitionNode.php index f21ae83..4ecd8fd 100644 --- a/src/Language/AST/EnumTypeDefinitionNode.php +++ b/src/Language/AST/EnumTypeDefinitionNode.php @@ -15,7 +15,7 @@ class EnumTypeDefinitionNode extends Node implements TypeDefinitionNode /** @var DirectiveNode[] */ public $directives; - /** @var EnumValueDefinitionNode[]|null|NodeList */ + /** @var EnumValueDefinitionNode[]|NodeList|null */ public $values; /** @var StringValueNode|null */ diff --git a/src/Language/AST/Location.php b/src/Language/AST/Location.php index 9eb7e1c..7ea05ad 100644 --- a/src/Language/AST/Location.php +++ b/src/Language/AST/Location.php @@ -51,6 +51,7 @@ class Location /** * @param int $start * @param int $end + * * @return static */ public static function create($start, $end) diff --git a/src/Language/AST/Node.php b/src/Language/AST/Node.php index c61d149..826478b 100644 --- a/src/Language/AST/Node.php +++ b/src/Language/AST/Node.php @@ -61,6 +61,7 @@ abstract class Node /** * @param string|NodeList|Location|Node|(Node|NodeList|Location)[] $value + * * @return string|NodeList|Location|Node */ private function cloneValue($value) @@ -94,6 +95,7 @@ abstract class Node /** * @param bool $recursive + * * @return mixed[] */ public function toArray($recursive = false) diff --git a/src/Language/AST/NodeList.php b/src/Language/AST/NodeList.php index 5028022..2e7de79 100644 --- a/src/Language/AST/NodeList.php +++ b/src/Language/AST/NodeList.php @@ -4,19 +4,24 @@ declare(strict_types=1); namespace GraphQL\Language\AST; +use ArrayAccess; +use Countable; +use Generator; use GraphQL\Utils\AST; +use IteratorAggregate; use function array_merge; use function array_splice; use function count; use function is_array; -class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable +class NodeList implements ArrayAccess, IteratorAggregate, Countable { /** @var Node[]|mixed[] */ private $nodes; /** * @param Node[]|mixed[] $nodes + * * @return static */ public static function create(array $nodes) @@ -25,7 +30,6 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable } /** - * * @param Node[]|mixed[] $nodes */ public function __construct(array $nodes) @@ -35,6 +39,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable /** * @param mixed $offset + * * @return bool */ public function offsetExists($offset) @@ -44,6 +49,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable /** * @param mixed $offset + * * @return mixed */ public function offsetGet($offset) @@ -81,6 +87,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable * @param int $offset * @param int $length * @param mixed $replacement + * * @return NodeList */ public function splice($offset, $length, $replacement = null) @@ -90,6 +97,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable /** * @param NodeList|Node[] $list + * * @return NodeList */ public function merge($list) @@ -101,7 +109,7 @@ class NodeList implements \ArrayAccess, \IteratorAggregate, \Countable } /** - * @return \Generator + * @return Generator */ public function getIterator() { diff --git a/src/Language/DirectiveLocation.php b/src/Language/DirectiveLocation.php index 77a0caf..5f22537 100644 --- a/src/Language/DirectiveLocation.php +++ b/src/Language/DirectiveLocation.php @@ -55,6 +55,7 @@ class DirectiveLocation /** * @param string $name + * * @return bool */ public static function has($name) diff --git a/src/Language/Lexer.php b/src/Language/Lexer.php index 223b6f8..d3b80ac 100644 --- a/src/Language/Lexer.php +++ b/src/Language/Lexer.php @@ -92,10 +92,8 @@ class Lexer */ public function advance() { - $this->lastToken = $this->token; - $token = $this->token = $this->lookahead(); - - return $token; + $this->lastToken = $this->token; + return $this->token = $this->lookahead(); } public function lookahead() @@ -112,6 +110,7 @@ class Lexer /** * @return Token + * * @throws SyntaxError */ private function readToken(Token $prev) @@ -129,7 +128,7 @@ class Lexer } // Read next char and advance string cursor: - list (, $code, $bytes) = $this->readChar(true); + [, $code, $bytes] = $this->readChar(true); // SourceCharacter if ($code < 0x0020 && $code !== 0x0009 && $code !== 0x000A && $code !== 0x000D) { @@ -156,8 +155,8 @@ class Lexer case 41: // ) return new Token(Token::PAREN_R, $position, $position + 1, $line, $col, $prev); case 46: // . - list (, $charCode1) = $this->readChar(true); - list (, $charCode2) = $this->readChar(true); + [, $charCode1] = $this->readChar(true); + [, $charCode2] = $this->readChar(true); if ($charCode1 === 46 && $charCode2 === 46) { return new Token(Token::SPREAD, $position, $position + 3, $line, $col, $prev); @@ -254,8 +253,8 @@ class Lexer ->readNumber($line, $col, $prev); // " case 34: - list(, $nextCode) = $this->readChar(); - list(, $nextNextCode) = $this->moveStringCursor(1, 1)->readChar(); + [, $nextCode] = $this->readChar(); + [, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar(); if ($nextCode === 34 && $nextNextCode === 34) { return $this->moveStringCursor(-2, (-1 * $bytes) - 1) @@ -284,13 +283,14 @@ class Lexer * * @param int $line * @param int $col + * * @return Token */ private function readName($line, $col, Token $prev) { - $value = ''; - $start = $this->position; - list ($char, $code) = $this->readChar(); + $value = ''; + $start = $this->position; + [$char, $code] = $this->readChar(); while ($code && ( $code === 95 || // _ @@ -298,8 +298,8 @@ class Lexer $code >= 65 && $code <= 90 || // A-Z $code >= 97 && $code <= 122 // a-z )) { - $value .= $char; - list ($char, $code) = $this->moveStringCursor(1, 1)->readChar(); + $value .= $char; + [$char, $code] = $this->moveStringCursor(1, 1)->readChar(); } return new Token( @@ -322,26 +322,28 @@ class Lexer * * @param int $line * @param int $col + * * @return Token + * * @throws SyntaxError */ private function readNumber($line, $col, Token $prev) { - $value = ''; - $start = $this->position; - list ($char, $code) = $this->readChar(); + $value = ''; + $start = $this->position; + [$char, $code] = $this->readChar(); $isFloat = false; if ($code === 45) { // - - $value .= $char; - list ($char, $code) = $this->moveStringCursor(1, 1)->readChar(); + $value .= $char; + [$char, $code] = $this->moveStringCursor(1, 1)->readChar(); } // guard against leading zero's if ($code === 48) { // 0 - $value .= $char; - list ($char, $code) = $this->moveStringCursor(1, 1)->readChar(); + $value .= $char; + [$char, $code] = $this->moveStringCursor(1, 1)->readChar(); if ($code >= 48 && $code <= 57) { throw new SyntaxError( @@ -351,23 +353,23 @@ class Lexer ); } } else { - $value .= $this->readDigits(); - list ($char, $code) = $this->readChar(); + $value .= $this->readDigits(); + [$char, $code] = $this->readChar(); } if ($code === 46) { // . $isFloat = true; $this->moveStringCursor(1, 1); - $value .= $char; - $value .= $this->readDigits(); - list ($char, $code) = $this->readChar(); + $value .= $char; + $value .= $this->readDigits(); + [$char, $code] = $this->readChar(); } if ($code === 69 || $code === 101) { // E e - $isFloat = true; - $value .= $char; - list ($char, $code) = $this->moveStringCursor(1, 1)->readChar(); + $isFloat = true; + $value .= $char; + [$char, $code] = $this->moveStringCursor(1, 1)->readChar(); if ($code === 43 || $code === 45) { // + - $value .= $char; @@ -392,14 +394,14 @@ class Lexer */ private function readDigits() { - list ($char, $code) = $this->readChar(); + [$char, $code] = $this->readChar(); if ($code >= 48 && $code <= 57) { // 0 - 9 $value = ''; do { - $value .= $char; - list ($char, $code) = $this->moveStringCursor(1, 1)->readChar(); + $value .= $char; + [$char, $code] = $this->moveStringCursor(1, 1)->readChar(); } while ($code >= 48 && $code <= 57); // 0 - 9 return $value; @@ -419,7 +421,9 @@ class Lexer /** * @param int $line * @param int $col + * * @return Token + * * @throws SyntaxError */ private function readString($line, $col, Token $prev) @@ -458,8 +462,8 @@ class Lexer $this->moveStringCursor(1, $bytes); if ($code === 92) { // \ - $value .= $chunk; - list (, $code) = $this->readChar(true); + $value .= $chunk; + [, $code] = $this->readChar(true); switch ($code) { case 34: @@ -487,8 +491,8 @@ class Lexer $value .= "\t"; break; case 117: - $position = $this->position; - list ($hex) = $this->readChars(4, true); + $position = $this->position; + [$hex] = $this->readChars(4, true); if (! preg_match('/[0-9a-fA-F]{4}/', $hex)) { throw new SyntaxError( $this->source, @@ -512,7 +516,7 @@ class Lexer $chunk .= $char; } - list ($char, $code, $bytes) = $this->readChar(); + [$char, $code, $bytes] = $this->readChar(); } throw new SyntaxError( @@ -532,7 +536,7 @@ class Lexer $start = $this->position; // Skip leading quotes and read first string char: - list ($char, $code, $bytes) = $this->moveStringCursor(3, 3)->readChar(); + [$char, $code, $bytes] = $this->moveStringCursor(3, 3)->readChar(); $chunk = ''; $value = ''; @@ -541,8 +545,8 @@ class Lexer // Closing Triple-Quote (""") if ($code === 34) { // Move 2 quotes - list(, $nextCode) = $this->moveStringCursor(1, 1)->readChar(); - list(, $nextNextCode) = $this->moveStringCursor(1, 1)->readChar(); + [, $nextCode] = $this->moveStringCursor(1, 1)->readChar(); + [, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar(); if ($nextCode === 34 && $nextNextCode === 34) { $value .= $chunk; @@ -567,9 +571,9 @@ class Lexer $this->assertValidBlockStringCharacterCode($code, $this->position); $this->moveStringCursor(1, $bytes); - list(, $nextCode) = $this->readChar(); - list(, $nextNextCode) = $this->moveStringCursor(1, 1)->readChar(); - list(, $nextNextNextCode) = $this->moveStringCursor(1, 1)->readChar(); + [, $nextCode] = $this->readChar(); + [, $nextNextCode] = $this->moveStringCursor(1, 1)->readChar(); + [, $nextNextNextCode] = $this->moveStringCursor(1, 1)->readChar(); // Escape Triple-Quote (\""") if ($code === 92 && @@ -585,7 +589,7 @@ class Lexer $chunk .= $char; } - list ($char, $code, $bytes) = $this->readChar(); + [$char, $code, $bytes] = $this->readChar(); } throw new SyntaxError( @@ -626,7 +630,7 @@ class Lexer private function positionAfterWhitespace() { while ($this->position < $this->source->length) { - list(, $code, $bytes) = $this->readChar(); + [, $code, $bytes] = $this->readChar(); // Skip whitespace // tab | space | comma | BOM @@ -637,7 +641,7 @@ class Lexer $this->line++; $this->lineStart = $this->position; } elseif ($code === 13) { // carriage return - list(, $nextCode, $nextBytes) = $this->moveStringCursor(1, $bytes)->readChar(); + [, $nextCode, $nextBytes] = $this->moveStringCursor(1, $bytes)->readChar(); if ($nextCode === 10) { // lf after cr $this->moveStringCursor(1, $nextBytes); @@ -657,6 +661,7 @@ class Lexer * * @param int $line * @param int $col + * * @return Token */ private function readComment($line, $col, Token $prev) @@ -666,8 +671,8 @@ class Lexer $bytes = 1; do { - list ($char, $code, $bytes) = $this->moveStringCursor(1, $bytes)->readChar(); - $value .= $char; + [$char, $code, $bytes] = $this->moveStringCursor(1, $bytes)->readChar(); + $value .= $char; } while ($code && // SourceCharacter but not LineTerminator ($code > 0x001F || $code === 0x0009) @@ -689,6 +694,7 @@ class Lexer * * @param bool $advance * @param int $byteStreamPosition + * * @return (string|int)[] */ private function readChar($advance = false, $byteStreamPosition = null) @@ -736,6 +742,7 @@ class Lexer * @param int $charCount * @param bool $advance * @param null $byteStreamPosition + * * @return (string|int)[] */ private function readChars($charCount, $advance = false, $byteStreamPosition = null) @@ -745,10 +752,10 @@ class Lexer $byteOffset = $byteStreamPosition ?: $this->byteStreamPosition; for ($i = 0; $i < $charCount; $i++) { - list ($char, $code, $bytes) = $this->readChar(false, $byteOffset); - $totalBytes += $bytes; - $byteOffset += $bytes; - $result .= $char; + [$char, $code, $bytes] = $this->readChar(false, $byteOffset); + $totalBytes += $bytes; + $byteOffset += $bytes; + $result .= $char; } if ($advance) { $this->moveStringCursor($charCount, $totalBytes); @@ -762,6 +769,7 @@ class Lexer * * @param int $positionOffset * @param int $byteStreamOffset + * * @return self */ private function moveStringCursor($positionOffset, $byteStreamOffset) diff --git a/src/Language/Parser.php b/src/Language/Parser.php index 9471981..10f0859 100644 --- a/src/Language/Parser.php +++ b/src/Language/Parser.php @@ -102,11 +102,14 @@ class Parser * Note: this feature is experimental and may change or be removed in the * future.) * - * @api * @param Source|string $source * @param bool[] $options + * * @return DocumentNode + * * @throws SyntaxError + * + * @api */ public static function parse($source, array $options = []) { @@ -126,10 +129,12 @@ class Parser * * Consider providing the results to the utility function: `GraphQL\Utils\AST::valueFromAST()`. * - * @api * @param Source|string $source * @param bool[] $options + * * @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|ObjectValueNode|StringValueNode|VariableNode + * + * @api */ public static function parseValue($source, array $options = []) { @@ -152,10 +157,12 @@ class Parser * * Consider providing the results to the utility function: `GraphQL\Utils\AST::typeFromAST()`. * - * @api * @param Source|string $source * @param bool[] $options + * * @return ListTypeNode|NameNode|NonNullTypeNode + * + * @api */ public static function parseType($source, array $options = []) { @@ -172,7 +179,6 @@ class Parser private $lexer; /** - * * @param bool[] $options */ public function __construct(Source $source, array $options = []) @@ -199,6 +205,7 @@ class Parser * Determines if the next token is of a given kind * * @param string $kind + * * @return bool */ private function peek($kind) @@ -211,6 +218,7 @@ class Parser * the parser. Otherwise, do not change the parser state and return false. * * @param string $kind + * * @return bool */ private function skip($kind) @@ -227,8 +235,11 @@ class Parser /** * If the next token is of the given kind, return that token after advancing * the parser. Otherwise, do not change the parser state and return false. + * * @param string $kind + * * @return Token + * * @throws SyntaxError */ private function expect($kind) @@ -254,7 +265,9 @@ class Parser * false. * * @param string $value + * * @return Token + * * @throws SyntaxError */ private function expectKeyword($value) @@ -292,7 +305,9 @@ class Parser * @param string $openKind * @param callable $parseFn * @param string $closeKind + * * @return NodeList + * * @throws SyntaxError */ private function any($openKind, $parseFn, $closeKind) @@ -316,7 +331,9 @@ class Parser * @param string $openKind * @param callable $parseFn * @param string $closeKind + * * @return NodeList + * * @throws SyntaxError */ private function many($openKind, $parseFn, $closeKind) @@ -335,6 +352,7 @@ class Parser * Converts a name lex token into a name parse node. * * @return NameNode + * * @throws SyntaxError */ private function parseName() @@ -351,6 +369,7 @@ class Parser * Implements the parsing rules in the Document section. * * @return DocumentNode + * * @throws SyntaxError */ private function parseDocument() @@ -371,6 +390,7 @@ class Parser /** * @return ExecutableDefinitionNode|TypeSystemDefinitionNode + * * @throws SyntaxError */ private function parseDefinition() @@ -408,6 +428,7 @@ class Parser /** * @return ExecutableDefinitionNode + * * @throws SyntaxError */ private function parseExecutableDefinition() @@ -433,6 +454,7 @@ class Parser /** * @return OperationDefinitionNode + * * @throws SyntaxError */ private function parseOperationDefinition() @@ -468,6 +490,7 @@ class Parser /** * @return string + * * @throws SyntaxError */ private function parseOperationType() @@ -503,6 +526,7 @@ class Parser /** * @return VariableDefinitionNode + * * @throws SyntaxError */ private function parseVariableDefinition() @@ -524,6 +548,7 @@ class Parser /** * @return VariableNode + * * @throws SyntaxError */ private function parseVariable() @@ -575,6 +600,7 @@ class Parser /** * @return FieldNode + * * @throws SyntaxError */ private function parseField() @@ -602,7 +628,9 @@ class Parser /** * @param bool $isConst + * * @return ArgumentNode[]|NodeList + * * @throws SyntaxError */ private function parseArguments($isConst) @@ -622,6 +650,7 @@ class Parser /** * @return ArgumentNode + * * @throws SyntaxError */ private function parseArgument() @@ -641,6 +670,7 @@ class Parser /** * @return ArgumentNode + * * @throws SyntaxError */ private function parseConstArgument() @@ -662,6 +692,7 @@ class Parser /** * @return FragmentSpreadNode|InlineFragmentNode + * * @throws SyntaxError */ private function parseFragment() @@ -693,6 +724,7 @@ class Parser /** * @return FragmentDefinitionNode + * * @throws SyntaxError */ private function parseFragmentDefinition() @@ -724,6 +756,7 @@ class Parser /** * @return NameNode + * * @throws SyntaxError */ private function parseFragmentName() @@ -756,7 +789,9 @@ class Parser * EnumValue : Name but not `true`, `false` or `null` * * @param bool $isConst + * * @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|StringValueNode|VariableNode|ListValueNode|ObjectValueNode|NullValueNode + * * @throws SyntaxError */ private function parseValueLiteral($isConst) @@ -834,6 +869,7 @@ class Parser /** * @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|StringValueNode|VariableNode + * * @throws SyntaxError */ private function parseConstValue() @@ -851,6 +887,7 @@ class Parser /** * @param bool $isConst + * * @return ListValueNode */ private function parseArray($isConst) @@ -872,6 +909,7 @@ class Parser /** * @param bool $isConst + * * @return ObjectValueNode */ private function parseObject($isConst) @@ -891,6 +929,7 @@ class Parser /** * @param bool $isConst + * * @return ObjectFieldNode */ private function parseObjectField($isConst) @@ -911,7 +950,9 @@ class Parser /** * @param bool $isConst + * * @return DirectiveNode[]|NodeList + * * @throws SyntaxError */ private function parseDirectives($isConst) @@ -926,7 +967,9 @@ class Parser /** * @param bool $isConst + * * @return DirectiveNode + * * @throws SyntaxError */ private function parseDirective($isConst) @@ -947,6 +990,7 @@ class Parser * Handles the Type: TypeName, ListType, and NonNullType parsing rules. * * @return ListTypeNode|NameNode|NonNullTypeNode + * * @throws SyntaxError */ private function parseTypeReference() @@ -1001,6 +1045,7 @@ class Parser * - InputObjectTypeDefinition * * @return TypeSystemDefinitionNode + * * @throws SyntaxError */ private function parseTypeSystemDefinition() @@ -1056,6 +1101,7 @@ class Parser /** * @return SchemaDefinitionNode + * * @throws SyntaxError */ private function parseSchemaDefinition() @@ -1081,6 +1127,7 @@ class Parser /** * @return OperationTypeDefinitionNode + * * @throws SyntaxError */ private function parseOperationTypeDefinition() @@ -1099,6 +1146,7 @@ class Parser /** * @return ScalarTypeDefinitionNode + * * @throws SyntaxError */ private function parseScalarTypeDefinition() @@ -1119,6 +1167,7 @@ class Parser /** * @return ObjectTypeDefinitionNode + * * @throws SyntaxError */ private function parseObjectTypeDefinition() @@ -1168,6 +1217,7 @@ class Parser /** * @return FieldDefinitionNode[]|NodeList + * * @throws SyntaxError */ private function parseFieldsDefinition() @@ -1196,6 +1246,7 @@ class Parser /** * @return FieldDefinitionNode + * * @throws SyntaxError */ private function parseFieldDefinition() @@ -1220,6 +1271,7 @@ class Parser /** * @return InputValueDefinitionNode[]|NodeList + * * @throws SyntaxError */ private function parseArgumentDefs() @@ -1239,6 +1291,7 @@ class Parser /** * @return InputValueDefinitionNode + * * @throws SyntaxError */ private function parseInputValueDef() @@ -1266,6 +1319,7 @@ class Parser /** * @return InterfaceTypeDefinitionNode + * * @throws SyntaxError */ private function parseInterfaceTypeDefinition() @@ -1291,6 +1345,7 @@ class Parser * - Description? union Name Directives[Const]? UnionMemberTypes? * * @return UnionTypeDefinitionNode + * * @throws SyntaxError */ private function parseUnionTypeDefinition() @@ -1334,6 +1389,7 @@ class Parser /** * @return EnumTypeDefinitionNode + * * @throws SyntaxError */ private function parseEnumTypeDefinition() @@ -1356,6 +1412,7 @@ class Parser /** * @return EnumValueDefinitionNode[]|NodeList + * * @throws SyntaxError */ private function parseEnumValuesDefinition() @@ -1373,6 +1430,7 @@ class Parser /** * @return EnumValueDefinitionNode + * * @throws SyntaxError */ private function parseEnumValueDefinition() @@ -1392,6 +1450,7 @@ class Parser /** * @return InputObjectTypeDefinitionNode + * * @throws SyntaxError */ private function parseInputObjectTypeDefinition() @@ -1414,6 +1473,7 @@ class Parser /** * @return InputValueDefinitionNode[]|NodeList + * * @throws SyntaxError */ private function parseInputFieldsDefinition() @@ -1439,6 +1499,7 @@ class Parser * - InputObjectTypeDefinition * * @return TypeExtensionNode + * * @throws SyntaxError */ private function parseTypeExtension() @@ -1469,6 +1530,7 @@ class Parser /** * @return SchemaTypeExtensionNode + * * @throws SyntaxError */ private function parseSchemaTypeExtension() @@ -1496,6 +1558,7 @@ class Parser /** * @return ScalarTypeExtensionNode + * * @throws SyntaxError */ private function parseScalarTypeExtension() @@ -1518,6 +1581,7 @@ class Parser /** * @return ObjectTypeExtensionNode + * * @throws SyntaxError */ private function parseObjectTypeExtension() @@ -1548,6 +1612,7 @@ class Parser /** * @return InterfaceTypeExtensionNode + * * @throws SyntaxError */ private function parseInterfaceTypeExtension() @@ -1578,6 +1643,7 @@ class Parser * - extend union Name Directives[Const] * * @return UnionTypeExtensionNode + * * @throws SyntaxError */ private function parseUnionTypeExtension() @@ -1604,6 +1670,7 @@ class Parser /** * @return EnumTypeExtensionNode + * * @throws SyntaxError */ private function parseEnumTypeExtension() @@ -1630,6 +1697,7 @@ class Parser /** * @return InputObjectTypeExtensionNode + * * @throws SyntaxError */ private function parseInputObjectTypeExtension() @@ -1659,6 +1727,7 @@ class Parser * - directive @ Name ArgumentsDefinition? on DirectiveLocations * * @return DirectiveDefinitionNode + * * @throws SyntaxError */ private function parseDirectiveDefinition() @@ -1683,6 +1752,7 @@ class Parser /** * @return NameNode[] + * * @throws SyntaxError */ private function parseDirectiveLocations() @@ -1699,6 +1769,7 @@ class Parser /** * @return NameNode + * * @throws SyntaxError */ private function parseDirectiveLocation() diff --git a/src/Language/Printer.php b/src/Language/Printer.php index f3148ed..891f411 100644 --- a/src/Language/Printer.php +++ b/src/Language/Printer.php @@ -73,9 +73,11 @@ class Printer /** * Prints AST to string. Capable of printing GraphQL queries and Type definition language. * - * @api * @param Node $ast + * * @return string + * + * @api */ public static function doPrint($ast) { @@ -95,11 +97,11 @@ class Printer $ast, [ 'leave' => [ - NodeKind::NAME => function (Node $node) { + NodeKind::NAME => static function (Node $node) { return '' . $node->value; }, - NodeKind::VARIABLE => function ($node) { + NodeKind::VARIABLE => static function ($node) { return '$' . $node->name; }, @@ -143,7 +145,7 @@ class Printer ); }, - NodeKind::ARGUMENT => function (ArgumentNode $node) { + NodeKind::ARGUMENT => static function (ArgumentNode $node) { return $node->name . ': ' . $node->value; }, @@ -172,11 +174,11 @@ class Printer . $node->selectionSet; }, - NodeKind::INT => function (IntValueNode $node) { + NodeKind::INT => static function (IntValueNode $node) { return $node->value; }, - NodeKind::FLOAT => function (FloatValueNode $node) { + NodeKind::FLOAT => static function (FloatValueNode $node) { return $node->value; }, @@ -188,15 +190,15 @@ class Printer return json_encode($node->value); }, - NodeKind::BOOLEAN => function (BooleanValueNode $node) { + NodeKind::BOOLEAN => static function (BooleanValueNode $node) { return $node->value ? 'true' : 'false'; }, - NodeKind::NULL => function (NullValueNode $node) { + NodeKind::NULL => static function (NullValueNode $node) { return 'null'; }, - NodeKind::ENUM => function (EnumValueNode $node) { + NodeKind::ENUM => static function (EnumValueNode $node) { return $node->value; }, @@ -208,7 +210,7 @@ class Printer return '{' . $this->join($node->fields, ', ') . '}'; }, - NodeKind::OBJECT_FIELD => function (ObjectFieldNode $node) { + NodeKind::OBJECT_FIELD => static function (ObjectFieldNode $node) { return $node->name . ': ' . $node->value; }, @@ -216,15 +218,15 @@ class Printer return '@' . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')'); }, - NodeKind::NAMED_TYPE => function (NamedTypeNode $node) { + NodeKind::NAMED_TYPE => static function (NamedTypeNode $node) { return $node->name; }, - NodeKind::LIST_TYPE => function (ListTypeNode $node) { + NodeKind::LIST_TYPE => static function (ListTypeNode $node) { return '[' . $node->type . ']'; }, - NodeKind::NON_NULL_TYPE => function (NonNullTypeNode $node) { + NodeKind::NON_NULL_TYPE => static function (NonNullTypeNode $node) { return $node->type . '!'; }, @@ -239,7 +241,7 @@ class Printer ); }, - NodeKind::OPERATION_TYPE_DEFINITION => function (OperationTypeDefinitionNode $def) { + NodeKind::OPERATION_TYPE_DEFINITION => static function (OperationTypeDefinitionNode $def) { return $def->operation . ': ' . $def->type; }, @@ -432,7 +434,7 @@ class Printer ); } - public function addDescription(\Closure $cb) + public function addDescription(callable $cb) { return function ($node) use ($cb) { return $this->join([$node->description, $cb($node)], "\n"); @@ -454,7 +456,7 @@ class Printer */ public function block($array) { - return ($array && $this->length($array)) + return $array && $this->length($array) ? "{\n" . $this->indent($this->join($array, "\n")) . "\n}" : ''; } @@ -481,7 +483,7 @@ class Printer $separator, Utils::filter( $maybeArray, - function ($x) { + static function ($x) { return (bool) $x; } ) @@ -498,7 +500,7 @@ class Printer { $escaped = str_replace('"""', '\\"""', $value); - return (($value[0] === ' ' || $value[0] === "\t") && strpos($value, "\n") === false) + return ($value[0] === ' ' || $value[0] === "\t") && strpos($value, "\n") === false ? ('"""' . preg_replace('/"$/', "\"\n", $escaped) . '"""') : ('"""' . "\n" . ($isDescription ? $escaped : $this->indent($escaped)) . "\n" . '"""'); } diff --git a/src/Language/Source.php b/src/Language/Source.php index 1beb8bc..7e94030 100644 --- a/src/Language/Source.php +++ b/src/Language/Source.php @@ -27,8 +27,6 @@ class Source public $locationOffset; /** - * - * * A representation of source input to GraphQL. * `name` and `locationOffset` are optional. They are useful for clients who * store GraphQL documents in source files; for example, if the GraphQL input @@ -63,6 +61,7 @@ class Source /** * @param int $position + * * @return SourceLocation */ public function getLocation($position) diff --git a/src/Language/SourceLocation.php b/src/Language/SourceLocation.php index 2c406ca..8877f84 100644 --- a/src/Language/SourceLocation.php +++ b/src/Language/SourceLocation.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace GraphQL\Language; -class SourceLocation implements \JsonSerializable +use JsonSerializable; + +class SourceLocation implements JsonSerializable { /** @var int */ public $line; diff --git a/src/Language/Token.php b/src/Language/Token.php index a1c966c..831b3ad 100644 --- a/src/Language/Token.php +++ b/src/Language/Token.php @@ -85,7 +85,6 @@ class Token public $next; /** - * * @param string $kind * @param int $start * @param int $end diff --git a/src/Language/Visitor.php b/src/Language/Visitor.php index 1a27f5a..e652d66 100644 --- a/src/Language/Visitor.php +++ b/src/Language/Visitor.php @@ -5,10 +5,12 @@ declare(strict_types=1); namespace GraphQL\Language; use ArrayObject; +use Exception; use GraphQL\Language\AST\Node; use GraphQL\Language\AST\NodeKind; use GraphQL\Language\AST\NodeList; use GraphQL\Utils\TypeInfo; +use SplFixedArray; use stdClass; use function array_pop; use function array_splice; @@ -172,12 +174,15 @@ class Visitor /** * Visit the AST (see class description for details) * - * @api * @param Node|ArrayObject|stdClass $root * @param callable[] $visitor * @param mixed[]|null $keyMap + * * @return Node|mixed - * @throws \Exception + * + * @throws Exception + * + * @api */ public static function visit($root, $visitor, $keyMap = null) { @@ -247,7 +252,7 @@ class Visitor $stack = $stack['prev']; } else { $key = $parent ? ($inArray ? $index : $keys[$index]) : $UNDEFINED; - $node = $parent ? (($parent instanceof NodeList || is_array($parent)) ? $parent[$key] : $parent->{$key}) : $newRoot; + $node = $parent ? ($parent instanceof NodeList || is_array($parent) ? $parent[$key] : $parent->{$key}) : $newRoot; if ($node === null || $node === $UNDEFINED) { continue; } @@ -259,7 +264,7 @@ class Visitor $result = null; if (! $node instanceof NodeList && ! is_array($node)) { if (! ($node instanceof Node)) { - throw new \Exception('Invalid AST Node: ' . json_encode($node)); + throw new Exception('Invalid AST Node: ' . json_encode($node)); } $visitFn = self::getVisitFn($visitor, $node->kind, $isLeaving); @@ -333,8 +338,9 @@ class Visitor /** * Returns marker for visitor break * - * @api * @return VisitorOperation + * + * @api */ public static function stop() { @@ -347,8 +353,9 @@ class Visitor /** * Returns marker for skipping current node * - * @api * @return VisitorOperation + * + * @api */ public static function skipNode() { @@ -361,8 +368,9 @@ class Visitor /** * Returns marker for removing a node * - * @api * @return VisitorOperation + * + * @api */ public static function removeNode() { @@ -374,15 +382,16 @@ class Visitor /** * @param callable[][] $visitors + * * @return callable[][] */ public static function visitInParallel($visitors) { $visitorsCount = count($visitors); - $skipping = new \SplFixedArray($visitorsCount); + $skipping = new SplFixedArray($visitorsCount); return [ - 'enter' => function (Node $node) use ($visitors, $skipping, $visitorsCount) { + 'enter' => static function (Node $node) use ($visitors, $skipping, $visitorsCount) { for ($i = 0; $i < $visitorsCount; $i++) { if (! empty($skipping[$i])) { continue; @@ -413,7 +422,7 @@ class Visitor } } }, - 'leave' => function (Node $node) use ($visitors, $skipping, $visitorsCount) { + 'leave' => static function (Node $node) use ($visitors, $skipping, $visitorsCount) { for ($i = 0; $i < $visitorsCount; $i++) { if (empty($skipping[$i])) { $fn = self::getVisitFn( @@ -449,7 +458,7 @@ class Visitor public static function visitWithTypeInfo(TypeInfo $typeInfo, $visitor) { return [ - 'enter' => function (Node $node) use ($typeInfo, $visitor) { + 'enter' => static function (Node $node) use ($typeInfo, $visitor) { $typeInfo->enter($node); $fn = self::getVisitFn($visitor, $node->kind, false); @@ -467,7 +476,7 @@ class Visitor return null; }, - 'leave' => function (Node $node) use ($typeInfo, $visitor) { + 'leave' => static function (Node $node) use ($typeInfo, $visitor) { $fn = self::getVisitFn($visitor, $node->kind, true); $result = $fn ? call_user_func_array($fn, func_get_args()) : null; $typeInfo->leave($node); @@ -481,6 +490,7 @@ class Visitor * @param callable[]|null $visitor * @param string $kind * @param bool $isLeaving + * * @return callable|null */ public static function getVisitFn($visitor, $kind, $isLeaving)