33namespace BenSampo \Enum \Commands ;
44
55use 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 ;
107use Illuminate \Console \Command ;
118use Illuminate \Filesystem \Filesystem ;
12- use Composer \ClassMapGenerator \ClassMapGenerator ;
9+ use Laminas \Code \Generator \DocBlock \Tag \MethodTag ;
10+ use Laminas \Code \Generator \DocBlock \Tag \TagInterface ;
1311use Laminas \Code \Generator \DocBlockGenerator ;
1412use Laminas \Code \Reflection \DocBlockReflection ;
15- use Symfony \Component \Console \Input \InputOption ;
1613use Symfony \Component \Console \Input \InputArgument ;
14+ use Symfony \Component \Console \Input \InputOption ;
1715
1816class EnumAnnotateCommand extends Command
1917{
@@ -23,19 +21,15 @@ class EnumAnnotateCommand extends Command
2321
2422 protected Filesystem $ filesystem ;
2523
26- /**
27- * @return array<int, array<int, mixed>>
28- */
24+ /** @return array<int, array<int, mixed>> */
2925 protected function getArguments (): array
3026 {
3127 return [
3228 ['class ' , InputArgument::OPTIONAL , 'The class name to generate annotations for ' ],
3329 ];
3430 }
3531
36- /**
37- * @return array<int, array<int, mixed>>
38- */
32+ /** @return array<int, array<int, mixed>> */
3933 protected function getOptions (): array
4034 {
4135 return [
@@ -61,30 +55,28 @@ public function handle(Filesystem $filesystem): int
6155
6256 protected function annotateClass (string $ className ): void
6357 {
64- if (!is_subclass_of ($ className , Enum::class)) {
58+ if (! is_subclass_of ($ className , Enum::class)) {
6559 $ 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 }. " );
6761 }
6862
69- $ reflection = new ReflectionClass ($ className );
63+ $ reflection = new \ ReflectionClass ($ className );
7064 $ this ->annotate ($ reflection );
7165 }
7266
7367 protected function annotateFolder (): void
7468 {
7569 foreach (ClassMapGenerator::createMap ($ this ->searchDirectory ()) as $ class => $ _ ) {
76- $ reflection = new ReflectionClass ($ class );
70+ $ reflection = new \ ReflectionClass ($ class );
7771
7872 if ($ reflection ->isSubclassOf (Enum::class)) {
7973 $ this ->annotate ($ reflection );
8074 }
8175 }
8276 }
8377
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
8880 {
8981 $ docBlock = $ this ->getDocBlock ($ reflectionClass );
9082 $ shortName = $ reflectionClass ->getShortName ();
@@ -119,10 +111,8 @@ protected function annotate(ReflectionClass $reflectionClass): void
119111 $ this ->info ("Wrote new phpDocBlock to {$ fileName }. " );
120112 }
121113
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
126116 {
127117 $ docBlock = DocBlockGenerator::fromArray ([])
128118 ->setWordWrap (false );
@@ -156,9 +146,10 @@ protected function getDocblockWithoutTags(DocBlockReflection $docBlockReflection
156146
157147 /**
158148 * @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass
149+ *
159150 * @return array<\Laminas\Code\Generator\DocBlock\Tag\TagInterface>
160151 */
161- protected function getDocblockTags (DocBlockGenerator |null $ originalDocblock , ReflectionClass $ reflectionClass ): array
152+ protected function getDocblockTags (DocBlockGenerator |null $ originalDocblock , \ ReflectionClass $ reflectionClass ): array
162153 {
163154 $ constants = $ reflectionClass ->getConstants ();
164155 $ constantKeys = array_keys ($ constants );
@@ -172,8 +163,7 @@ protected function getDocblockTags(DocBlockGenerator|null $originalDocblock, Ref
172163 if ($ originalDocblock ) {
173164 $ tags = array_merge (
174165 $ 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
177167 || ! in_array ($ tag ->getMethodName (), $ constantKeys , true ))
178168 );
179169 }
0 commit comments