Skip to content

Commit 59ef891

Browse files
authored
Merge branch refs/heads/1.12.x into 2.0.x
2 parents 4d312be + 381c137 commit 59ef891

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/Parser/RichParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ public function parseString(string $sourceCode): array
9898
}
9999

100100
foreach ($traitCollectingVisitor->traits as $trait) {
101-
$trait->setAttribute('linesToIgnore', array_filter($linesToIgnore, static fn (int $line): bool => $line >= $trait->getStartLine() && $line <= $trait->getEndLine(), ARRAY_FILTER_USE_KEY));
101+
$preexisting = $trait->getAttribute('linesToIgnore', []);
102+
$filteredLinesToIgnore = array_filter($linesToIgnore, static fn (int $line): bool => $line >= $trait->getStartLine() && $line <= $trait->getEndLine(), ARRAY_FILTER_USE_KEY);
103+
foreach ($preexisting as $line => $ignores) {
104+
$filteredLinesToIgnore[$line] = $ignores;
105+
}
106+
$trait->setAttribute('linesToIgnore', $filteredLinesToIgnore);
102107
}
103108

104109
return $nodes;

tests/PHPStan/Parser/RichParserTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,45 @@ public function dataLinesToIgnore(): iterable
271271
2 => ['identifier'],
272272
],
273273
];
274+
275+
yield [
276+
'<?php' . PHP_EOL .
277+
PHP_EOL .
278+
'class MyClass {' . PHP_EOL .
279+
' use MyTrait;' . PHP_EOL .
280+
PHP_EOL .
281+
' public mixed $myProperty;' . PHP_EOL .
282+
PHP_EOL .
283+
' function myFunction(): void {' . PHP_EOL .
284+
' // @phpstan-ignore variable.undefined' . PHP_EOL .
285+
' $this->myProperty = $b;' . PHP_EOL .
286+
' }' . PHP_EOL .
287+
'}',
288+
[
289+
10 => ['variable.undefined'],
290+
],
291+
];
292+
293+
yield [
294+
'<?php' . PHP_EOL .
295+
PHP_EOL .
296+
'trait MyTrait {' . PHP_EOL .
297+
'}' . PHP_EOL .
298+
PHP_EOL .
299+
'class MyClass {' . PHP_EOL .
300+
' use MyTrait;' . PHP_EOL .
301+
PHP_EOL .
302+
' public mixed $myProperty;' . PHP_EOL .
303+
PHP_EOL .
304+
' function myFunction(): void {' . PHP_EOL .
305+
' // @phpstan-ignore variable.undefined' . PHP_EOL .
306+
' $this->myProperty = $b;' . PHP_EOL .
307+
' }' . PHP_EOL .
308+
'}',
309+
[
310+
13 => ['variable.undefined'],
311+
],
312+
];
274313
}
275314

276315
/**

0 commit comments

Comments
 (0)