Skip to content

Commit f06c4a2

Browse files
committed
Skip polyfills in vendor when on a higher PHP version
1 parent 02869f6 commit f06c4a2

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

build/baseline-pre-8.0.neon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,21 @@ parameters:
133133
message: '#^Parameter \#1 \$array \(non-empty-list<PHPStan\\Type\\Type>\) of array_values is already a list, call has no effect\.$#'
134134
count: 1
135135
path: ../src/Type/TypeCombinator.php
136+
137+
-
138+
rawMessage: Access to property $id of internal class Symfony\Polyfill\Php80\PhpToken from outside its root namespace Symfony.
139+
identifier: property.internalClass
140+
count: 1
141+
path: ../src/Parser/RichParser.php
142+
143+
-
144+
rawMessage: Access to property $line of internal class Symfony\Polyfill\Php80\PhpToken from outside its root namespace Symfony.
145+
identifier: property.internalClass
146+
count: 4
147+
path: ../src/Parser/RichParser.php
148+
149+
-
150+
rawMessage: Access to property $text of internal class Symfony\Polyfill\Php80\PhpToken from outside its root namespace Symfony.
151+
identifier: property.internalClass
152+
count: 3
153+
path: ../src/Parser/RichParser.php

phpstan-baseline.neon

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,6 @@ parameters:
264264
count: 1
265265
path: src/Fixable/PhpPrinterIndentationDetectorVisitor.php
266266

267-
-
268-
rawMessage: Access to property $id of internal class Symfony\Polyfill\Php80\PhpToken from outside its root namespace Symfony.
269-
identifier: property.internalClass
270-
count: 1
271-
path: src/Parser/RichParser.php
272-
273-
-
274-
rawMessage: Access to property $line of internal class Symfony\Polyfill\Php80\PhpToken from outside its root namespace Symfony.
275-
identifier: property.internalClass
276-
count: 4
277-
path: src/Parser/RichParser.php
278-
279-
-
280-
rawMessage: Access to property $text of internal class Symfony\Polyfill\Php80\PhpToken from outside its root namespace Symfony.
281-
identifier: property.internalClass
282-
count: 3
283-
path: src/Parser/RichParser.php
284-
285267
-
286268
rawMessage: 'Call to function method_exists() with PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode and ''getParamOutTypeTagV…'' will always evaluate to true.'
287269
identifier: function.alreadyNarrowedType

src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
1616
use PHPStan\DependencyInjection\AutowiredParameter;
1717
use PHPStan\DependencyInjection\AutowiredService;
18+
use PHPStan\Php\PhpVersion;
1819
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadFunctionsSourceLocator;
1920
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator;
2021
use PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker;
@@ -26,8 +27,10 @@
2627
use PHPStan\Reflection\BetterReflection\SourceLocator\ReflectionClassSourceLocator;
2728
use PHPStan\Reflection\BetterReflection\SourceLocator\RewriteClassAliasSourceLocator;
2829
use PHPStan\Reflection\BetterReflection\SourceLocator\SkipClassAliasSourceLocator;
30+
use PHPStan\Reflection\BetterReflection\SourceLocator\SkipPolyfillSourceLocator;
2931
use function array_merge;
3032
use function array_unique;
33+
use function count;
3134
use function extension_loaded;
3235
use function is_dir;
3336
use function is_file;
@@ -49,6 +52,7 @@ public function __construct(
4952
private Parser $parser,
5053
#[AutowiredParameter(ref: '@php8PhpParser')]
5154
private Parser $php8Parser,
55+
private PhpVersion $phpVersion,
5256
private PhpStormStubsSourceStubber $phpstormStubsSourceStubber,
5357
private ReflectionSourceStubber $reflectionSourceStubber,
5458
private OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
@@ -126,12 +130,18 @@ public function create(): SourceLocator
126130

127131
$astPhp8Locator = new Locator($this->php8Parser);
128132

133+
$composerLocators = [];
134+
129135
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
130136
$locator = $this->composerJsonAndInstalledJsonSourceLocatorMaker->create($composerAutoloaderProjectPath);
131137
if ($locator === null) {
132138
continue;
133139
}
134-
$fileLocators[] = $locator;
140+
$composerLocators[] = $locator;
141+
}
142+
143+
if (count($composerLocators) > 0) {
144+
$fileLocators[] = new SkipPolyfillSourceLocator(new AggregateSourceLocator($composerLocators), $this->phpVersion);
135145
}
136146

137147
if (extension_loaded('phar')) {

0 commit comments

Comments
 (0)