1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Reflection;
4:
5: use PHPStan\BetterReflection\Reflection\Adapter\ReflectionEnumBackedCase;
6: use PHPStan\BetterReflection\Reflection\Adapter\ReflectionEnumUnitCase;
7: use PHPStan\Internal\DeprecatedAttributeHelper;
8: use PHPStan\Reflection\Deprecation\DeprecationProvider;
9: use PHPStan\TrinaryLogic;
10: use PHPStan\Type\Type;
11:
12: /**
13: * @api
14: */
15: final class EnumCaseReflection
16: {
17:
18: private bool $isDeprecated;
19:
20: private ?string $deprecatedDescription;
21:
22: /**
23: * @param list<AttributeReflection> $attributes
24: */
25: public function __construct(
26: private ClassReflection $declaringEnum,
27: private ReflectionEnumUnitCase|ReflectionEnumBackedCase $reflection,
28: private ?Type $backingValueType,
29: private array $attributes,
30: DeprecationProvider $deprecationProvider,
31: )
32: {
33: $deprecation = $deprecationProvider->getEnumCaseDeprecation($reflection);
34: if ($deprecation !== null) {
35: $this->isDeprecated = true;
36: $this->deprecatedDescription = $deprecation->getDescription();
37:
38: } elseif ($reflection->isDeprecated()) {
39: $attributes = $this->reflection->getBetterReflection()->getAttributes();
40: $this->isDeprecated = true;
41: $this->deprecatedDescription = DeprecatedAttributeHelper::getDeprecatedDescription($attributes);
42: } else {
43: $this->isDeprecated = false;
44: $this->deprecatedDescription = null;
45: }
46: }
47:
48: public function getDeclaringEnum(): ClassReflection
49: {
50: return $this->declaringEnum;
51: }
52:
53: public function getName(): string
54: {
55: return $this->reflection->getName();
56: }
57:
58: public function getBackingValueType(): ?Type
59: {
60: return $this->backingValueType;
61: }
62:
63: public function isDeprecated(): TrinaryLogic
64: {
65: return TrinaryLogic::createFromBoolean($this->isDeprecated);
66: }
67:
68: public function getDeprecatedDescription(): ?string
69: {
70: return $this->deprecatedDescription;
71: }
72:
73: /**
74: * @return list<AttributeReflection>
75: */
76: public function getAttributes(): array
77: {
78: return $this->attributes;
79: }
80:
81: }
82: