77use ReflectionClassConstant as CoreReflectionClassConstant ;
88use Roave \BetterReflection \Reflection \ReflectionAttribute as BetterReflectionAttribute ;
99use Roave \BetterReflection \Reflection \ReflectionClassConstant as BetterReflectionClassConstant ;
10+ use Roave \BetterReflection \Reflection \ReflectionEnumCase as BetterReflectionEnumCase ;
1011
1112use function array_map ;
1213
1314final class ReflectionClassConstant extends CoreReflectionClassConstant
1415{
15- public function __construct (private BetterReflectionClassConstant $ betterClassConstant )
16+ public function __construct (private BetterReflectionClassConstant | BetterReflectionEnumCase $ betterClassConstantOrEnumCase )
1617 {
1718 }
1819
@@ -22,7 +23,7 @@ public function __construct(private BetterReflectionClassConstant $betterClassCo
2223 */
2324 public function getName (): string
2425 {
25- return $ this ->betterClassConstant ->getName ();
26+ return $ this ->betterClassConstantOrEnumCase ->getName ();
2627 }
2728
2829 /**
@@ -32,55 +33,71 @@ public function getName(): string
3233 */
3334 public function getValue (): string |int |float |bool |array |null
3435 {
35- return $ this ->betterClassConstant ->getValue ();
36+ return $ this ->betterClassConstantOrEnumCase ->getValue ();
3637 }
3738
3839 /**
3940 * Constant is public
4041 */
4142 public function isPublic (): bool
4243 {
43- return $ this ->betterClassConstant ->isPublic ();
44+ if ($ this ->betterClassConstantOrEnumCase instanceof BetterReflectionEnumCase) {
45+ return true ;
46+ }
47+
48+ return $ this ->betterClassConstantOrEnumCase ->isPublic ();
4449 }
4550
4651 /**
4752 * Constant is private
4853 */
4954 public function isPrivate (): bool
5055 {
51- return $ this ->betterClassConstant ->isPrivate ();
56+ if ($ this ->betterClassConstantOrEnumCase instanceof BetterReflectionEnumCase) {
57+ return false ;
58+ }
59+
60+ return $ this ->betterClassConstantOrEnumCase ->isPrivate ();
5261 }
5362
5463 /**
5564 * Constant is protected
5665 */
5766 public function isProtected (): bool
5867 {
59- return $ this ->betterClassConstant ->isProtected ();
68+ if ($ this ->betterClassConstantOrEnumCase instanceof BetterReflectionEnumCase) {
69+ return false ;
70+ }
71+
72+ return $ this ->betterClassConstantOrEnumCase ->isProtected ();
6073 }
6174
6275 /**
6376 * Returns a bitfield of the access modifiers for this constant
6477 */
6578 public function getModifiers (): int
6679 {
67- return $ this ->betterClassConstant ->getModifiers ();
80+ if ($ this ->betterClassConstantOrEnumCase instanceof BetterReflectionEnumCase) {
81+ return CoreReflectionClassConstant::IS_PUBLIC ;
82+ }
83+
84+ return $ this ->betterClassConstantOrEnumCase ->getModifiers ();
6885 }
6986
7087 /**
7188 * Get the declaring class
7289 */
7390 public function getDeclaringClass (): ReflectionClass
7491 {
75- return new ReflectionClass ($ this ->betterClassConstant ->getDeclaringClass ());
92+ return new ReflectionClass ($ this ->betterClassConstantOrEnumCase ->getDeclaringClass ());
7693 }
7794
7895 /**
7996 * Returns the doc comment for this constant
8097 */
8198 public function getDocComment (): string |false
8299 {
83- return $ this ->betterClassConstant ->getDocComment () ?: false ;
100+ return $ this ->betterClassConstantOrEnumCase ->getDocComment () ?: false ;
84101 }
85102
86103 /**
@@ -90,7 +107,7 @@ public function getDocComment(): string|false
90107 */
91108 public function __toString (): string
92109 {
93- return $ this ->betterClassConstant ->__toString ();
110+ return $ this ->betterClassConstantOrEnumCase ->__toString ();
94111 }
95112
96113 /**
@@ -101,23 +118,27 @@ public function __toString(): string
101118 public function getAttributes (?string $ name = null , int $ flags = 0 ): array
102119 {
103120 if ($ name !== null && $ flags & ReflectionAttribute::IS_INSTANCEOF ) {
104- $ attributes = $ this ->betterClassConstant ->getAttributesByInstance ($ name );
121+ $ attributes = $ this ->betterClassConstantOrEnumCase ->getAttributesByInstance ($ name );
105122 } elseif ($ name !== null ) {
106- $ attributes = $ this ->betterClassConstant ->getAttributesByName ($ name );
123+ $ attributes = $ this ->betterClassConstantOrEnumCase ->getAttributesByName ($ name );
107124 } else {
108- $ attributes = $ this ->betterClassConstant ->getAttributes ();
125+ $ attributes = $ this ->betterClassConstantOrEnumCase ->getAttributes ();
109126 }
110127
111128 return array_map (static fn (BetterReflectionAttribute $ betterReflectionAttribute ): ReflectionAttribute => new ReflectionAttribute ($ betterReflectionAttribute ), $ attributes );
112129 }
113130
114131 public function isFinal (): bool
115132 {
116- return $ this ->betterClassConstant ->isFinal ();
133+ if ($ this ->betterClassConstantOrEnumCase instanceof BetterReflectionEnumCase) {
134+ return true ;
135+ }
136+
137+ return $ this ->betterClassConstantOrEnumCase ->isFinal ();
117138 }
118139
119140 public function isEnumCase (): bool
120141 {
121- throw new Exception \ NotImplemented ( ' Not implemented ' ) ;
142+ return $ this -> betterClassConstantOrEnumCase instanceof BetterReflectionEnumCase ;
122143 }
123144}
0 commit comments