1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace PHPStan\BetterReflection\Reflection\Adapter;
6:
7: use Attribute;
8: use PhpParser\Node\Expr;
9: use ReflectionAttribute as CoreReflectionAttribute;
10: use PHPStan\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
11:
12: /** @template-extends CoreReflectionAttribute<object> */
13: final class ReflectionAttribute extends CoreReflectionAttribute
14: {
15: /**
16: * @var BetterReflectionAttribute
17: */
18: private $betterReflectionAttribute;
19: public function __construct(BetterReflectionAttribute $betterReflectionAttribute)
20: {
21: $this->betterReflectionAttribute = $betterReflectionAttribute;
22: }
23:
24: /** @psalm-mutation-free */
25: public function getName(): string
26: {
27: return $this->betterReflectionAttribute->getName();
28: }
29:
30: /**
31: * @return int-mask-of<Attribute::TARGET_*>
32: *
33: * @psalm-mutation-free
34: * @psalm-suppress ImplementedReturnTypeMismatch
35: */
36: public function getTarget(): int
37: {
38: return $this->betterReflectionAttribute->getTarget();
39: }
40:
41: /** @psalm-mutation-free */
42: public function isRepeated(): bool
43: {
44: return $this->betterReflectionAttribute->isRepeated();
45: }
46:
47: /**
48: * @return array<int|string, mixed>
49: */
50: public function getArguments(): array
51: {
52: return $this->betterReflectionAttribute->getArguments();
53: }
54:
55: /** @return array<int|string, Expr> */
56: public function getArgumentsExpressions(): array
57: {
58: return $this->betterReflectionAttribute->getArgumentsExpressions();
59: }
60:
61: public function newInstance(): object
62: {
63: $class = $this->getName();
64:
65: return new $class(...$this->getArguments());
66: }
67:
68: /** @return non-empty-string */
69: public function __toString(): string
70: {
71: return $this->betterReflectionAttribute->__toString();
72: }
73: }
74: