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: * @deprecated Use getArgumentsExpressions()
49: * @return array<int|string, mixed>
50: */
51: public function getArguments(): array
52: {
53: return $this->betterReflectionAttribute->getArguments();
54: }
55:
56: /** @return array<int|string, Expr> */
57: public function getArgumentsExpressions(): array
58: {
59: return $this->betterReflectionAttribute->getArgumentsExpressions();
60: }
61:
62: public function newInstance(): object
63: {
64: $class = $this->getName();
65:
66: return new $class(...$this->getArguments());
67: }
68:
69: /** @return non-empty-string */
70: public function __toString(): string
71: {
72: return $this->betterReflectionAttribute->__toString();
73: }
74: }
75: