-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
AbstractReflectionClass.php
85 lines (69 loc) · 2.97 KB
/
AbstractReflectionClass.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Phpactor\WorseReflection\Bridge\TolerantParser\Reflection;
use Phpactor\WorseReflection\Core\Reflection\Collection\ReflectionMethodCollection;
use Phpactor\WorseReflection\Bridge\TolerantParser\Reflection\TraitImport\TraitImports;
use Phpactor\WorseReflection\Core\ClassName;
use Phpactor\WorseReflection\Core\Deprecation;
use Phpactor\WorseReflection\Core\DocBlock\DocBlock;
use Phpactor\WorseReflection\Core\Exception\NotFound;
use Phpactor\WorseReflection\Core\Reflection\Collection\ReflectionMethodCollection as PhpactorReflectionMethodCollection;
use Phpactor\WorseReflection\Core\Reflection\Collection\ReflectionTraitCollection;
use Phpactor\WorseReflection\Core\Reflection\ReflectionClassLike;
use Phpactor\WorseReflection\Core\TemplateMap;
use Phpactor\WorseReflection\Core\TypeFactory;
use Phpactor\WorseReflection\Core\Type\ReflectedClassType;
use Phpactor\WorseReflection\Core\Virtual\VirtualReflectionMethod;
abstract class AbstractReflectionClass extends AbstractReflectedNode implements ReflectionClassLike
{
abstract public function name(): ClassName;
abstract public function docblock(): DocBlock;
public function isClass(): bool
{
return $this instanceof ReflectionClass;
}
public function isConcrete(): bool
{
return false;
}
public function deprecation(): Deprecation
{
return $this->docblock()->deprecation();
}
public function templateMap(): TemplateMap
{
return $this->docblock()->templateMap();
}
public function type(): ReflectedClassType
{
return TypeFactory::reflectedClass($this->serviceLocator()->reflector(), $this->name());
}
abstract public function classLikeType(): string;
protected function resolveTraitMethods(
TraitImports $traitImports,
ReflectionClassLike $contextClass,
ReflectionTraitCollection $traits
): PhpactorReflectionMethodCollection {
$methods = ReflectionMethodCollection::empty();
foreach ($traitImports as $traitImport) {
try {
$trait = $traits->get($traitImport->name());
} catch (NotFound) {
continue;
}
$traitMethods = [];
foreach ($trait->methods($contextClass) as $method) {
if (false === $traitImport->hasAliasFor($method->name())) {
$traitMethods[] = $method;
continue;
}
$traitAlias = $traitImport->getAlias($method->name());
$virtualMethod = VirtualReflectionMethod::fromReflectionMethod($trait->methods()->get($traitAlias->originalName()))
->withName($traitAlias->newName())
->withVisibility($traitAlias->visiblity($method->visibility()));
$traitMethods[] = $virtualMethod;
}
$methods = $methods->merge(ReflectionMethodCollection::fromReflectionMethods($traitMethods));
}
return $methods;
}
}