From 2862a7bf7927a7e76771b71f43206d01dfc5d6ef Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 25 Jul 2023 09:25:20 +0200 Subject: [PATCH] Changed `linesToIgnore` attribute format --- src/Analyser/FileAnalyser.php | 4 ++-- src/Parser/RichParser.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Analyser/FileAnalyser.php b/src/Analyser/FileAnalyser.php index 0e8281fb83..351d8a5be8 100644 --- a/src/Analyser/FileAnalyser.php +++ b/src/Analyser/FileAnalyser.php @@ -242,10 +242,10 @@ private function getLinesToIgnoreFromTokens(array $nodes): array return []; } - /** @var int[] $tokenLines */ + /** @var array|null> $tokenLines */ $tokenLines = $nodes[0]->getAttribute('linesToIgnore', []); $lines = []; - foreach ($tokenLines as $tokenLine) { + foreach (array_keys($tokenLines) as $tokenLine) { $lines[$tokenLine] = true; } diff --git a/src/Parser/RichParser.php b/src/Parser/RichParser.php index 643afe1294..f39f27613d 100644 --- a/src/Parser/RichParser.php +++ b/src/Parser/RichParser.php @@ -11,10 +11,10 @@ use PHPStan\File\FileReader; use PHPStan\ShouldNotHappenException; use function array_filter; -use function array_values; use function is_string; use function strpos; use function substr_count; +use const ARRAY_FILTER_USE_KEY; use const T_COMMENT; use const T_DOC_COMMENT; @@ -78,7 +78,7 @@ public function parseString(string $sourceCode): array } foreach ($traitCollectingVisitor->traits as $trait) { - $trait->setAttribute('linesToIgnore', array_values(array_filter($linesToIgnore, static fn (int $line): bool => $line >= $trait->getStartLine() && $line <= $trait->getEndLine()))); + $trait->setAttribute('linesToIgnore', array_filter($linesToIgnore, static fn (int $line): bool => $line >= $trait->getStartLine() && $line <= $trait->getEndLine(), ARRAY_FILTER_USE_KEY)); } return $nodes; @@ -86,7 +86,7 @@ public function parseString(string $sourceCode): array /** * @param mixed[] $tokens - * @return int[] + * @return array|null> */ private function getLinesToIgnore(array $tokens): array { @@ -111,7 +111,7 @@ private function getLinesToIgnore(array $tokens): array $line += substr_count($token[1], "\n"); - $lines[] = $line; + $lines[$line] = null; } return $lines;