From 1f296663356734e9015db96f06c42dd72de6dbc1 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Thu, 14 Sep 2017 23:05:37 -0700 Subject: [PATCH] Fix incorrect PHPdoc for src/Parser.php, nit on property assignment Clarify phpdoc of parseDelimitedList Don't assign a DelimitedList to node->nameParts, it's declared as an array. (Has no side effects, this is overwritten afterwards unless nameParts was null) --- src/Parser.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 2c4cbfbb..6e4782af 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -345,7 +345,6 @@ private function getParseListElementFn($context) { /** * Aborts parsing list when one of the parent contexts understands something - * @param ParseContext $context * @return bool */ private function isCurrentTokenValidInEnclosingContexts() { @@ -367,7 +366,7 @@ private function isInParseContext($contextToCheck) { * Retrieve the current token, and check that it's of the expected TokenKind. * If so, advance and return the token. Otherwise return a MissingToken for * the expected token. - * @param int $kind + * @param int|int[] ...$kinds * @return Token */ private function eat(...$kinds) { @@ -385,6 +384,10 @@ private function eat(...$kinds) { return new MissingToken($kinds[0], $token->fullStart); } + /** + * @param int|int[] ...$kinds (Can provide a single value with a list of kinds, or multiple kinds) + * @return Token|null + */ private function eatOptional(...$kinds) { $token = $this->token; if (\is_array($kinds[0])) { @@ -849,6 +852,10 @@ private function isExpressionStartFn() { }; } + /** + * @param Node $parentNode + * @return Token|MissingToken|Node + */ private function parsePrimaryExpression($parentNode) { $token = $this->getCurrentToken(); switch ($token->kind) { @@ -1135,6 +1142,15 @@ private function isParameterStartFn() { }; } + /** + * @param string $className (name of subclass of DelimitedList) + * @param int $delimiter + * @param callable $isElementStartFn + * @param callable $parseElementFn + * @param Node $parentNode + * @param bool $allowEmptyElements + * @return DelimitedList|null instance of $className + */ private function parseDelimitedList($className, $delimiter, $isElementStartFn, $parseElementFn, $parentNode, $allowEmptyElements = false) { // TODO consider allowing empty delimiter to be more tolerant $node = new $className(); @@ -1191,7 +1207,7 @@ private function parseQualifiedNameFn() { $node->globalSpecifier = $this->eatOptional(TokenKind::BackslashToken); } - $node->nameParts = + $nameParts = $this->parseDelimitedList( DelimitedList\QualifiedNameParts::class, TokenKind::BackslashToken, @@ -1214,11 +1230,11 @@ function ($parentNode) { $name->kind = TokenKind::Name; // bool/true/null/static should not be treated as keywords in this case return $name; }, $node); - if ($node->nameParts === null && $node->globalSpecifier === null && $node->relativeSpecifier === null) { + if ($nameParts === null && $node->globalSpecifier === null && $node->relativeSpecifier === null) { return null; } - $node->nameParts = $node->nameParts ? $node->nameParts->children : []; + $node->nameParts = $nameParts ? $nameParts->children : []; return $node; };