13
13
use Laminas \Code \Generator \DocBlock \Tag \TagInterface ;
14
14
use Laminas \Code \Generator \DocBlockGenerator ;
15
15
use Laminas \Code \Reflection \DocBlockReflection ;
16
- use ReflectionClass ;
16
+ use ReflectionEnum ;
17
17
use ReflectionException ;
18
18
use UnitEnum ;
19
19
@@ -52,7 +52,7 @@ protected function annotateFolder(): int
52
52
53
53
if (count ($ searchDirectoryMap ) > 0 ) {
54
54
foreach ($ searchDirectoryMap as $ class => $ _ ) {
55
- $ reflection = new ReflectionClass ($ class );
55
+ $ reflection = new ReflectionEnum ($ class );
56
56
57
57
if ($ reflection ->isSubclassOf (UnitEnum::class)) {
58
58
$ this ->annotate ($ reflection );
@@ -79,38 +79,38 @@ protected function annotateClass(string $className): int
79
79
return self ::FAILURE ;
80
80
}
81
81
82
- $ reflection = new ReflectionClass ($ className );
82
+ $ reflection = new ReflectionEnum ($ className );
83
83
$ this ->annotate ($ reflection );
84
84
85
85
return self ::SUCCESS ;
86
86
}
87
87
88
88
/**
89
- * @param ReflectionClass <UnitEnum> $reflectionClass
89
+ * @param ReflectionEnum <UnitEnum> $reflectionEnum
90
90
*
91
91
* @throws FileNotFoundException
92
92
*/
93
- protected function annotate (ReflectionClass $ reflectionClass ): void
93
+ protected function annotate (ReflectionEnum $ reflectionEnum ): void
94
94
{
95
95
$ docBlock = new DocBlockGenerator ;
96
96
97
- if ($ reflectionClass ->getDocComment ()) {
97
+ if ($ reflectionEnum ->getDocComment ()) {
98
98
$ docBlock ->setShortDescription (
99
- DocBlockGenerator::fromReflection (new DocBlockReflection ($ reflectionClass ))
99
+ DocBlockGenerator::fromReflection (new DocBlockReflection ($ reflectionEnum ))
100
100
->getShortDescription ()
101
101
);
102
102
}
103
103
104
- $ this ->updateClassDocblock ($ reflectionClass , $ this ->getDocBlock ($ reflectionClass ));
104
+ $ this ->updateClassDocblock ($ reflectionEnum , $ this ->getDocBlock ($ reflectionEnum ));
105
105
}
106
106
107
107
/**
108
108
* @throws FileNotFoundException
109
109
*/
110
- protected function updateClassDocblock (ReflectionClass $ reflectionClass , DocBlockGenerator $ docBlock ): void
110
+ protected function updateClassDocblock (ReflectionEnum $ reflectionEnum , DocBlockGenerator $ docBlock ): void
111
111
{
112
- $ shortName = $ reflectionClass ->getShortName ();
113
- $ fileName = (string ) $ reflectionClass ->getFileName ();
112
+ $ shortName = $ reflectionEnum ->getShortName ();
113
+ $ fileName = (string ) $ reflectionEnum ->getFileName ();
114
114
$ contents = $ this ->filesystem ->get ($ fileName );
115
115
116
116
$ enumDeclaration = "enum {$ shortName }" ;
@@ -139,16 +139,16 @@ protected function updateClassDocblock(ReflectionClass $reflectionClass, DocBloc
139
139
}
140
140
}
141
141
142
- protected function getDocBlock (ReflectionClass $ reflectionClass ): DocBlockGenerator
142
+ protected function getDocBlock (ReflectionEnum $ reflectionEnum ): DocBlockGenerator
143
143
{
144
144
$ docBlock = (new DocBlockGenerator )
145
145
->setWordWrap (false );
146
146
147
147
$ originalDocBlock = null ;
148
148
149
- if ($ reflectionClass ->getDocComment ()) {
149
+ if ($ reflectionEnum ->getDocComment ()) {
150
150
$ originalDocBlock = DocBlockGenerator::fromReflection (
151
- new DocBlockReflection (ltrim ($ reflectionClass ->getDocComment ()))
151
+ new DocBlockReflection (ltrim ($ reflectionEnum ->getDocComment ()))
152
152
);
153
153
154
154
if ($ originalDocBlock ->getShortDescription ()) {
@@ -162,7 +162,7 @@ protected function getDocBlock(ReflectionClass $reflectionClass): DocBlockGenera
162
162
163
163
$ docBlock ->setTags ($ this ->getDocblockTags (
164
164
$ originalDocBlock ,
165
- $ reflectionClass
165
+ $ reflectionEnum
166
166
));
167
167
168
168
return $ docBlock ;
@@ -173,15 +173,15 @@ protected function getDocBlock(ReflectionClass $reflectionClass): DocBlockGenera
173
173
*/
174
174
protected function getDocblockTags (
175
175
?DocBlockGenerator $ originalDocblock ,
176
- ReflectionClass $ reflectionClass
176
+ ReflectionEnum $ reflectionEnum
177
177
): array {
178
- $ constants = $ reflectionClass ->getConstants ();
178
+ $ constants = $ reflectionEnum ->getConstants ();
179
179
$ constantKeys = array_keys ($ constants );
180
180
181
181
$ tags = array_map (
182
182
static fn (mixed $ value , string $ constantName ): MethodTag => new MethodTag (
183
183
(new Convert ($ constantName ))->toCamel (),
184
- ['string ' ],
184
+ $ reflectionEnum -> getBackingType ()?->getName() === ' int ' ? [ ' int ' ] : ['string ' ],
185
185
null ,
186
186
true
187
187
),
0 commit comments