3
3
namespace BenSampo \Enum \Commands ;
4
4
5
5
use BenSampo \Enum \Enum ;
6
- use Laminas \Code \Generator \DocBlock \Tag \MethodTag ;
7
- use Laminas \Code \Generator \DocBlock \Tag \TagInterface ;
8
- use ReflectionClass ;
9
- use InvalidArgumentException ;
6
+ use Composer \ClassMapGenerator \ClassMapGenerator ;
10
7
use Illuminate \Console \Command ;
11
8
use Illuminate \Filesystem \Filesystem ;
12
- use Composer \ClassMapGenerator \ClassMapGenerator ;
9
+ use Laminas \Code \Generator \DocBlock \Tag \MethodTag ;
10
+ use Laminas \Code \Generator \DocBlock \Tag \TagInterface ;
13
11
use Laminas \Code \Generator \DocBlockGenerator ;
14
12
use Laminas \Code \Reflection \DocBlockReflection ;
15
- use Symfony \Component \Console \Input \InputOption ;
16
13
use Symfony \Component \Console \Input \InputArgument ;
14
+ use Symfony \Component \Console \Input \InputOption ;
17
15
18
16
class EnumAnnotateCommand extends Command
19
17
{
@@ -23,19 +21,15 @@ class EnumAnnotateCommand extends Command
23
21
24
22
protected Filesystem $ filesystem ;
25
23
26
- /**
27
- * @return array<int, array<int, mixed>>
28
- */
24
+ /** @return array<int, array<int, mixed>> */
29
25
protected function getArguments (): array
30
26
{
31
27
return [
32
28
['class ' , InputArgument::OPTIONAL , 'The class name to generate annotations for ' ],
33
29
];
34
30
}
35
31
36
- /**
37
- * @return array<int, array<int, mixed>>
38
- */
32
+ /** @return array<int, array<int, mixed>> */
39
33
protected function getOptions (): array
40
34
{
41
35
return [
@@ -61,30 +55,28 @@ public function handle(Filesystem $filesystem): int
61
55
62
56
protected function annotateClass (string $ className ): void
63
57
{
64
- if (!is_subclass_of ($ className , Enum::class)) {
58
+ if (! is_subclass_of ($ className , Enum::class)) {
65
59
$ parentClass = Enum::class;
66
- throw new InvalidArgumentException ("The given class {$ className } must be an instance of {$ parentClass }. " );
60
+ throw new \ InvalidArgumentException ("The given class {$ className } must be an instance of {$ parentClass }. " );
67
61
}
68
62
69
- $ reflection = new ReflectionClass ($ className );
63
+ $ reflection = new \ ReflectionClass ($ className );
70
64
$ this ->annotate ($ reflection );
71
65
}
72
66
73
67
protected function annotateFolder (): void
74
68
{
75
69
foreach (ClassMapGenerator::createMap ($ this ->searchDirectory ()) as $ class => $ _ ) {
76
- $ reflection = new ReflectionClass ($ class );
70
+ $ reflection = new \ ReflectionClass ($ class );
77
71
78
72
if ($ reflection ->isSubclassOf (Enum::class)) {
79
73
$ this ->annotate ($ reflection );
80
74
}
81
75
}
82
76
}
83
77
84
- /**
85
- * @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass
86
- */
87
- protected function annotate (ReflectionClass $ reflectionClass ): void
78
+ /** @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass */
79
+ protected function annotate (\ReflectionClass $ reflectionClass ): void
88
80
{
89
81
$ docBlock = $ this ->getDocBlock ($ reflectionClass );
90
82
$ shortName = $ reflectionClass ->getShortName ();
@@ -119,10 +111,8 @@ protected function annotate(ReflectionClass $reflectionClass): void
119
111
$ this ->info ("Wrote new phpDocBlock to {$ fileName }. " );
120
112
}
121
113
122
- /**
123
- * @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass
124
- */
125
- protected function getDocBlock (ReflectionClass $ reflectionClass ): DocBlockGenerator
114
+ /** @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass */
115
+ protected function getDocBlock (\ReflectionClass $ reflectionClass ): DocBlockGenerator
126
116
{
127
117
$ docBlock = DocBlockGenerator::fromArray ([])
128
118
->setWordWrap (false );
@@ -156,9 +146,10 @@ protected function getDocblockWithoutTags(DocBlockReflection $docBlockReflection
156
146
157
147
/**
158
148
* @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass
149
+ *
159
150
* @return array<\Laminas\Code\Generator\DocBlock\Tag\TagInterface>
160
151
*/
161
- protected function getDocblockTags (DocBlockGenerator |null $ originalDocblock , ReflectionClass $ reflectionClass ): array
152
+ protected function getDocblockTags (DocBlockGenerator |null $ originalDocblock , \ ReflectionClass $ reflectionClass ): array
162
153
{
163
154
$ constants = $ reflectionClass ->getConstants ();
164
155
$ constantKeys = array_keys ($ constants );
@@ -172,8 +163,7 @@ protected function getDocblockTags(DocBlockGenerator|null $originalDocblock, Ref
172
163
if ($ originalDocblock ) {
173
164
$ tags = array_merge (
174
165
$ tags ,
175
- array_filter ($ originalDocblock ->getTags (), fn (TagInterface $ tag ): bool =>
176
- ! $ tag instanceof MethodTag
166
+ array_filter ($ originalDocblock ->getTags (), fn (TagInterface $ tag ): bool => ! $ tag instanceof MethodTag
177
167
|| ! in_array ($ tag ->getMethodName (), $ constantKeys , true ))
178
168
);
179
169
}
0 commit comments