1313use Laminas \Code \Generator \DocBlock \Tag \TagInterface ;
1414use Laminas \Code \Generator \DocBlockGenerator ;
1515use Laminas \Code \Reflection \DocBlockReflection ;
16- use ReflectionClass ;
16+ use ReflectionEnum ;
1717use ReflectionException ;
1818use UnitEnum ;
1919
@@ -52,7 +52,7 @@ protected function annotateFolder(): int
5252
5353 if (count ($ searchDirectoryMap ) > 0 ) {
5454 foreach ($ searchDirectoryMap as $ class => $ _ ) {
55- $ reflection = new ReflectionClass ($ class );
55+ $ reflection = new ReflectionEnum ($ class );
5656
5757 if ($ reflection ->isSubclassOf (UnitEnum::class)) {
5858 $ this ->annotate ($ reflection );
@@ -79,38 +79,38 @@ protected function annotateClass(string $className): int
7979 return self ::FAILURE ;
8080 }
8181
82- $ reflection = new ReflectionClass ($ className );
82+ $ reflection = new ReflectionEnum ($ className );
8383 $ this ->annotate ($ reflection );
8484
8585 return self ::SUCCESS ;
8686 }
8787
8888 /**
89- * @param ReflectionClass <UnitEnum> $reflectionClass
89+ * @param ReflectionEnum <UnitEnum> $reflectionEnum
9090 *
9191 * @throws FileNotFoundException
9292 */
93- protected function annotate (ReflectionClass $ reflectionClass ): void
93+ protected function annotate (ReflectionEnum $ reflectionEnum ): void
9494 {
9595 $ docBlock = new DocBlockGenerator ;
9696
97- if ($ reflectionClass ->getDocComment ()) {
97+ if ($ reflectionEnum ->getDocComment ()) {
9898 $ docBlock ->setShortDescription (
99- DocBlockGenerator::fromReflection (new DocBlockReflection ($ reflectionClass ))
99+ DocBlockGenerator::fromReflection (new DocBlockReflection ($ reflectionEnum ))
100100 ->getShortDescription ()
101101 );
102102 }
103103
104- $ this ->updateClassDocblock ($ reflectionClass , $ this ->getDocBlock ($ reflectionClass ));
104+ $ this ->updateClassDocblock ($ reflectionEnum , $ this ->getDocBlock ($ reflectionEnum ));
105105 }
106106
107107 /**
108108 * @throws FileNotFoundException
109109 */
110- protected function updateClassDocblock (ReflectionClass $ reflectionClass , DocBlockGenerator $ docBlock ): void
110+ protected function updateClassDocblock (ReflectionEnum $ reflectionEnum , DocBlockGenerator $ docBlock ): void
111111 {
112- $ shortName = $ reflectionClass ->getShortName ();
113- $ fileName = (string ) $ reflectionClass ->getFileName ();
112+ $ shortName = $ reflectionEnum ->getShortName ();
113+ $ fileName = (string ) $ reflectionEnum ->getFileName ();
114114 $ contents = $ this ->filesystem ->get ($ fileName );
115115
116116 $ enumDeclaration = "enum {$ shortName }" ;
@@ -139,16 +139,16 @@ protected function updateClassDocblock(ReflectionClass $reflectionClass, DocBloc
139139 }
140140 }
141141
142- protected function getDocBlock (ReflectionClass $ reflectionClass ): DocBlockGenerator
142+ protected function getDocBlock (ReflectionEnum $ reflectionEnum ): DocBlockGenerator
143143 {
144144 $ docBlock = (new DocBlockGenerator )
145145 ->setWordWrap (false );
146146
147147 $ originalDocBlock = null ;
148148
149- if ($ reflectionClass ->getDocComment ()) {
149+ if ($ reflectionEnum ->getDocComment ()) {
150150 $ originalDocBlock = DocBlockGenerator::fromReflection (
151- new DocBlockReflection (ltrim ($ reflectionClass ->getDocComment ()))
151+ new DocBlockReflection (ltrim ($ reflectionEnum ->getDocComment ()))
152152 );
153153
154154 if ($ originalDocBlock ->getShortDescription ()) {
@@ -162,7 +162,7 @@ protected function getDocBlock(ReflectionClass $reflectionClass): DocBlockGenera
162162
163163 $ docBlock ->setTags ($ this ->getDocblockTags (
164164 $ originalDocBlock ,
165- $ reflectionClass
165+ $ reflectionEnum
166166 ));
167167
168168 return $ docBlock ;
@@ -173,15 +173,15 @@ protected function getDocBlock(ReflectionClass $reflectionClass): DocBlockGenera
173173 */
174174 protected function getDocblockTags (
175175 ?DocBlockGenerator $ originalDocblock ,
176- ReflectionClass $ reflectionClass
176+ ReflectionEnum $ reflectionEnum
177177 ): array {
178- $ constants = $ reflectionClass ->getConstants ();
178+ $ constants = $ reflectionEnum ->getConstants ();
179179 $ constantKeys = array_keys ($ constants );
180180
181181 $ tags = array_map (
182182 static fn (mixed $ value , string $ constantName ): MethodTag => new MethodTag (
183183 (new Convert ($ constantName ))->toCamel (),
184- ['string ' ],
184+ $ reflectionEnum -> getBackingType ()?->getName() === ' int ' ? [ ' int ' ] : ['string ' ],
185185 null ,
186186 true
187187 ),
0 commit comments