55namespace ApiSkeletons \Laravel \Doctrine \ApiKey \Console \Command ;
66
77use ApiSkeletons \Laravel \Doctrine \ApiKey \Entity \ApiKey ;
8- use ApiSkeletons \Laravel \Doctrine \ApiKey \Service \ApiKeyService ;
9- use Illuminate \Console \Command ;
10-
11- use function implode ;
128
139// phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint
1410final class ActivateApiKey extends Command
1511{
16- private ApiKeyService $ apiKeyService ;
17-
1812 /**
1913 * The name and signature of the console command.
2014 */
@@ -25,18 +19,6 @@ final class ActivateApiKey extends Command
2519 */
2620 protected $ description = 'Activate an ApiKey ' ;
2721
28- /**
29- * Create a new command instance.
30- *
31- * @return void
32- */
33- public function __construct (ApiKeyService $ apiKeyService )
34- {
35- parent ::__construct ();
36-
37- $ this ->apiKeyService = $ apiKeyService ;
38- }
39-
4022 /**
4123 * Execute the console command.
4224 */
@@ -50,30 +32,15 @@ public function handle(): mixed
5032 $ apiKey = $ apiKeyRepository ->findOneBy (['name ' => $ name ]);
5133
5234 if (! $ apiKey ) {
53- $ this ->error ('Invalid apiKey name ' );
35+ $ this ->error ('Invalid apikey name ' );
5436
5537 return 1 ;
5638 }
5739
5840 $ apiKeyRepository ->updateActive ($ apiKey , true );
5941 $ this ->apiKeyService ->getEntityManager ()->flush ();
6042
61- $ scopeNames = [];
62- foreach ($ apiKey ->getScopes () as $ s ) {
63- $ scopeNames [] = $ s ->getName ();
64- }
65-
66- $ headers = ['name ' , 'key ' , 'status ' , 'scopes ' ];
67- $ rows = [
68- [
69- $ apiKey ->getName (),
70- $ apiKey ->getApiKey (),
71- $ apiKey ->getIsActive () ? 'active ' : 'deactivated ' ,
72- implode (', ' , $ scopeNames ),
73- ],
74- ];
75-
76- $ this ->table ($ headers , $ rows );
43+ $ this ->printApiKeys ([$ apiKey ]);
7744
7845 return 0 ;
7946 }
0 commit comments