Skip to content

Commit 5988ead

Browse files
committed
Cover remaining global constant scan cases
1 parent 083179b commit 5988ead

8 files changed

Lines changed: 43 additions & 4 deletions

File tree

‎.github/workflows/e2e-tests.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ jobs:
246246
- script: |
247247
cd e2e/bug-15231
248248
../../bin/phpstan analyze
249+
- script: |
250+
cd e2e/bug-15482
251+
../../bin/phpstan analyse
249252
- script: |
250253
cd e2e/bug-15102
251254
composer install

‎e2e/bug-15482/phpstan.neon‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src

‎e2e/bug-15482/src/a_usage.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
echo BAR;

‎e2e/bug-15482/src/z_functions.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
function foo(): string
4+
{
5+
return stdClass::class;
6+
}
7+
8+
const BAR = 'bar';

‎src/Reflection/BetterReflection/SourceLocator/PhpFileCleaner.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public function clean(string $contents, int $maxMatches): string
9797
if ($inType) {
9898
$typeLevel--;
9999

100-
if ($typeLevel === 0) {
100+
if ($typeLevel <= 0) {
101+
$typeLevel = 0;
101102
$inType = false;
102103
}
103104
}

‎tests/PHPStan/Reflection/BetterReflection/SourceLocator/SymbolFinderInFilesTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public static function dataFindSymbols(): iterable
1717
__DIR__ . '/data/symbol-finder/class-name-before-global-constant.php',
1818
[
1919
[],
20-
['symbolfinderclassname', 'classname', 'symbolfinderanonymousclass'],
21-
['AFTER_CLASS_NAME', 'AFTER_CLASS_PREFIX', 'AFTER_ANONYMOUS_CLASS'],
20+
['symbolfinderclassname', 'classname', 'symbolfinderanonymousclass', 'symbolfindernamedargument', 'symbolfindernamedargumentcall', 'symbolfinderspacedclassconstant'],
21+
['AFTER_CLASS_NAME', 'AFTER_CLASS_PREFIX', 'AFTER_ANONYMOUS_CLASS', 'AFTER_NAMED_CLASS_ARGUMENT', 'AFTER_SPACED_CLASS_CONSTANT'],
2222
],
2323
];
2424

‎tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/symbol-finder/class-name-before-global-constant.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,22 @@ function symbolFinderAnonymousClass(): object
2222
}
2323

2424
const AFTER_ANONYMOUS_CLASS = 'also found';
25+
26+
function symbolFinderNamedArgument(string $class): string
27+
{
28+
return $class;
29+
}
30+
31+
function symbolFinderNamedArgumentCall(): string
32+
{
33+
return symbolFinderNamedArgument(class: 'named argument');
34+
}
35+
36+
const AFTER_NAMED_CLASS_ARGUMENT = 'found after named argument';
37+
38+
function symbolFinderSpacedClassConstant(): string
39+
{
40+
return \stdClass:: class;
41+
}
42+
43+
const AFTER_SPACED_CLASS_CONSTANT = 'found after spaced class constant';

‎turbo-ext/src/SymbolScan.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ inline void PhpFileCleaner::clean(zend_long maxMatches, std::string &out)
378378
if (inType) {
379379
typeLevel--;
380380

381-
if (typeLevel == 0) {
381+
if (typeLevel <= 0) {
382+
typeLevel = 0;
382383
inType = false;
383384
}
384385
}

0 commit comments

Comments
 (0)