1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | namespace PHPStan\BetterReflection\Reflection\Adapter; |
6: | |
7: | use Attribute; |
8: | use OutOfBoundsException; |
9: | use PhpParser\Node\Expr; |
10: | use ReflectionAttribute as CoreReflectionAttribute; |
11: | use PHPStan\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute; |
12: | |
13: | use function sprintf; |
14: | |
15: | |
16: | final class ReflectionAttribute extends CoreReflectionAttribute |
17: | { |
18: | private BetterReflectionAttribute $betterReflectionAttribute; |
19: | public const TARGET_CONSTANT_COMPATIBILITY = 64; |
20: | |
21: | public function __construct(BetterReflectionAttribute $betterReflectionAttribute) |
22: | { |
23: | $this->betterReflectionAttribute = $betterReflectionAttribute; |
24: | unset($this->name); |
25: | } |
26: | |
27: | public function getBetterReflection(): BetterReflectionAttribute |
28: | { |
29: | return $this->betterReflectionAttribute; |
30: | } |
31: | |
32: | |
33: | public function getName(): string |
34: | { |
35: | return $this->betterReflectionAttribute->getName(); |
36: | } |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | public function getTarget(): int |
45: | { |
46: | return $this->betterReflectionAttribute->getTarget(); |
47: | } |
48: | |
49: | |
50: | public function isRepeated(): bool |
51: | { |
52: | return $this->betterReflectionAttribute->isRepeated(); |
53: | } |
54: | |
55: | |
56: | |
57: | |
58: | public function getArguments(): array |
59: | { |
60: | return $this->betterReflectionAttribute->getArguments(); |
61: | } |
62: | |
63: | |
64: | public function getArgumentsExpressions(): array |
65: | { |
66: | return $this->betterReflectionAttribute->getArgumentsExpressions(); |
67: | } |
68: | |
69: | public function newInstance(): object |
70: | { |
71: | $class = $this->getName(); |
72: | |
73: | return new $class(...$this->getArguments()); |
74: | } |
75: | |
76: | |
77: | public function __toString(): string |
78: | { |
79: | return $this->betterReflectionAttribute->__toString(); |
80: | } |
81: | |
82: | |
83: | |
84: | |
85: | public function __get(string $name) |
86: | { |
87: | if ($name === 'name') { |
88: | return $this->betterReflectionAttribute->getName(); |
89: | } |
90: | |
91: | throw new OutOfBoundsException(sprintf('Property %s::$%s does not exist.', self::class, $name)); |
92: | } |
93: | } |
94: | |