|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Reflection\BetterReflection\SourceLocator; |
| 4 | + |
| 5 | +use Override; |
| 6 | +use PHPStan\BetterReflection\Identifier\Identifier; |
| 7 | +use PHPStan\BetterReflection\Identifier\IdentifierType; |
| 8 | +use PHPStan\BetterReflection\Reflection\Reflection; |
| 9 | +use PHPStan\BetterReflection\Reflection\ReflectionClass; |
| 10 | +use PHPStan\BetterReflection\Reflection\ReflectionConstant; |
| 11 | +use PHPStan\BetterReflection\Reflection\ReflectionFunction; |
| 12 | +use PHPStan\BetterReflection\Reflector\Reflector; |
| 13 | +use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator; |
| 14 | +use PHPStan\Php\PhpVersion; |
| 15 | +use function str_contains; |
| 16 | +use function str_replace; |
| 17 | + |
| 18 | +final class SkipPolyfillSourceLocator implements SourceLocator |
| 19 | +{ |
| 20 | + |
| 21 | + public function __construct(private SourceLocator $sourceLocator, private PhpVersion $phpVersion) |
| 22 | + { |
| 23 | + } |
| 24 | + |
| 25 | + #[Override] |
| 26 | + public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection |
| 27 | + { |
| 28 | + $reflection = $this->sourceLocator->locateIdentifier($reflector, $identifier); |
| 29 | + if ($reflection === null) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + if ($reflection instanceof ReflectionClass || $reflection instanceof ReflectionFunction || $reflection instanceof ReflectionConstant) { |
| 34 | + $fileName = $reflection->getFileName(); |
| 35 | + if ($fileName !== null) { |
| 36 | + $normalized = str_replace('\\', '/', $fileName); |
| 37 | + if (str_contains($normalized, '/symfony/polyfill-php80/') && $this->phpVersion->getVersionId() >= 80000) { |
| 38 | + return null; |
| 39 | + } |
| 40 | + if (str_contains($normalized, '/symfony/polyfill-php81/') && $this->phpVersion->getVersionId() >= 80100) { |
| 41 | + return null; |
| 42 | + } |
| 43 | + if (str_contains($normalized, '/symfony/polyfill-php82/') && $this->phpVersion->getVersionId() >= 80200) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + if (str_contains($normalized, '/symfony/polyfill-php83/') && $this->phpVersion->getVersionId() >= 80300) { |
| 47 | + return null; |
| 48 | + } |
| 49 | + if (str_contains($normalized, '/symfony/polyfill-php84/') && $this->phpVersion->getVersionId() >= 80400) { |
| 50 | + return null; |
| 51 | + } |
| 52 | + if (str_contains($normalized, '/symfony/polyfill-php85/') && $this->phpVersion->getVersionId() >= 80500) { |
| 53 | + return null; |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return $reflection; |
| 59 | + } |
| 60 | + |
| 61 | + #[Override] |
| 62 | + public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array |
| 63 | + { |
| 64 | + return $this->sourceLocator->locateIdentifiersByType($reflector, $identifierType); |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments