| 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 function __construct(BetterReflectionAttribute $betterReflectionAttribute) |
| 20: | { |
| 21: | $this->betterReflectionAttribute = $betterReflectionAttribute; |
| 22: | unset($this->name); |
| 23: | } |
| 24: | |
| 25: | public function getBetterReflection(): BetterReflectionAttribute |
| 26: | { |
| 27: | return $this->betterReflectionAttribute; |
| 28: | } |
| 29: | |
| 30: | |
| 31: | public function getName(): string |
| 32: | { |
| 33: | return $this->betterReflectionAttribute->getName(); |
| 34: | } |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | public function getTarget(): int |
| 43: | { |
| 44: | return $this->betterReflectionAttribute->getTarget(); |
| 45: | } |
| 46: | |
| 47: | |
| 48: | public function isRepeated(): bool |
| 49: | { |
| 50: | return $this->betterReflectionAttribute->isRepeated(); |
| 51: | } |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | public function getArguments(): array |
| 57: | { |
| 58: | return $this->betterReflectionAttribute->getArguments(); |
| 59: | } |
| 60: | |
| 61: | |
| 62: | public function getArgumentsExpressions(): array |
| 63: | { |
| 64: | return $this->betterReflectionAttribute->getArgumentsExpressions(); |
| 65: | } |
| 66: | |
| 67: | public function newInstance(): object |
| 68: | { |
| 69: | $class = $this->getName(); |
| 70: | |
| 71: | return new $class(...$this->getArguments()); |
| 72: | } |
| 73: | |
| 74: | |
| 75: | public function __toString(): string |
| 76: | { |
| 77: | return $this->betterReflectionAttribute->__toString(); |
| 78: | } |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | public function __get(string $name) |
| 84: | { |
| 85: | if ($name === 'name') { |
| 86: | return $this->betterReflectionAttribute->getName(); |
| 87: | } |
| 88: | |
| 89: | throw new OutOfBoundsException(sprintf('Property %s::$%s does not exist.', self::class, $name)); |
| 90: | } |
| 91: | } |
| 92: | |