-
Notifications
You must be signed in to change notification settings - Fork 428
/
SkipClassAliasSourceLocator.php
48 lines (37 loc) · 1.45 KB
/
SkipClassAliasSourceLocator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php declare(strict_types = 1);
namespace PHPStan\Reflection\BetterReflection\SourceLocator;
use PHPStan\BetterReflection\Identifier\Identifier;
use PHPStan\BetterReflection\Identifier\IdentifierType;
use PHPStan\BetterReflection\Reflection\Reflection;
use PHPStan\BetterReflection\Reflector\Reflector;
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
class SkipClassAliasSourceLocator implements SourceLocator
{
private SourceLocator $sourceLocator;
public function __construct(SourceLocator $sourceLocator)
{
$this->sourceLocator = $sourceLocator;
}
public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection
{
if ($identifier->isClass()) {
$className = $identifier->getName();
if (!class_exists($className, false)) {
return $this->sourceLocator->locateIdentifier($reflector, $identifier);
}
$reflection = new \ReflectionClass($className);
if ($reflection->getName() === 'ReturnTypeWillChange') {
return $this->sourceLocator->locateIdentifier($reflector, $identifier);
}
if ($reflection->getFileName() === false) {
return $this->sourceLocator->locateIdentifier($reflector, $identifier);
}
return null;
}
return $this->sourceLocator->locateIdentifier($reflector, $identifier);
}
public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array
{
return $this->sourceLocator->locateIdentifiersByType($reflector, $identifierType);
}
}