Fix PhpStan errors

This commit is contained in:
Nikita Popov 2023-08-13 12:45:21 +02:00
parent 4b497045e0
commit 62853b179c
2 changed files with 13 additions and 11 deletions

View File

@ -158,7 +158,7 @@ abstract class ParserAbstract implements Parser {
$this->initReduceCallbacks(); $this->initReduceCallbacks();
$this->phpTokenToSymbol = $this->createTokenMap(); $this->phpTokenToSymbol = $this->createTokenMap();
$this->dropTokens = array_fill_keys( $this->dropTokens = array_fill_keys(
[\T_WHITESPACE, \T_OPEN_TAG, \T_COMMENT, \T_DOC_COMMENT, \T_BAD_CHARACTER], 1 [\T_WHITESPACE, \T_OPEN_TAG, \T_COMMENT, \T_DOC_COMMENT, \T_BAD_CHARACTER], true
); );
} }
@ -471,7 +471,7 @@ abstract class ParserAbstract implements Parser {
* *
* @param int $tokenStartPos Token position the node starts at * @param int $tokenStartPos Token position the node starts at
* @param int $tokenEndPos Token position the node ends at * @param int $tokenEndPos Token position the node ends at
* @return array Attributes * @return array<string, mixed> Attributes
*/ */
protected function getAttributes(int $tokenStartPos, int $tokenEndPos): array { protected function getAttributes(int $tokenStartPos, int $tokenEndPos): array {
$startToken = $this->tokens[$tokenStartPos]; $startToken = $this->tokens[$tokenStartPos];
@ -491,7 +491,12 @@ abstract class ParserAbstract implements Parser {
return $attributes; return $attributes;
} }
protected function getAttributesForToken(int $tokenPos) { /**
* Get attributes for a single token at the given token position.
*
* @return array<string, mixed> Attributes
*/
protected function getAttributesForToken(int $tokenPos): array {
if ($tokenPos < \count($this->tokens) - 1) { if ($tokenPos < \count($this->tokens) - 1) {
return $this->getAttributes($tokenPos, $tokenPos); return $this->getAttributes($tokenPos, $tokenPos);
} }
@ -896,6 +901,11 @@ abstract class ParserAbstract implements Parser {
$token->getEndLine(), $token->getEndPos() - 1, $tokenPos); $token->getEndLine(), $token->getEndPos() - 1, $tokenPos);
} }
/**
* Get comments before the given token position.
*
* @return Comment[] Comments
*/
protected function getCommentsBeforeToken(int $tokenPos): array { protected function getCommentsBeforeToken(int $tokenPos): array {
$comments = []; $comments = [];
while (--$tokenPos >= 0) { while (--$tokenPos >= 0) {
@ -913,9 +923,6 @@ abstract class ParserAbstract implements Parser {
/** /**
* Create a zero-length nop to capture preceding comments, if any. * Create a zero-length nop to capture preceding comments, if any.
*
* @param Comment[] $comments
* @return array<string, mixed>
*/ */
protected function maybeCreateZeroLengthNop(int $tokenPos): ?Nop { protected function maybeCreateZeroLengthNop(int $tokenPos): ?Nop {
$comments = $this->getCommentsBeforeToken($tokenPos); $comments = $this->getCommentsBeforeToken($tokenPos);

View File

@ -254,8 +254,3 @@ parameters:
message: "#^Variable \\$action might not be defined\\.$#" message: "#^Variable \\$action might not be defined\\.$#"
count: 1 count: 1
path: lib/PhpParser/ParserAbstract.php path: lib/PhpParser/ParserAbstract.php
-
message: "#^Variable \\$tokenValue might not be defined\\.$#"
count: 1
path: lib/PhpParser/ParserAbstract.php