@@ -56,7 +56,7 @@ public function verifyCommandToken(string $commandToken): array|false
5656 * @var array<string, mixed> $payload
5757 */
5858 $ payload = json_decode ($ payloadJson , true );
59- if ($ payload === null ) {
59+ if (! is_array ( $ payload) ) {
6060 error_log ('commands.verifyCommandToken: invalid JSON decoding ' );
6161 return false ;
6262 }
@@ -66,7 +66,8 @@ public function verifyCommandToken(string $commandToken): array|false
6666 return false ;
6767 }
6868
69- $ iss = (string ) $ payload ['iss ' ];
69+ /** @var string $iss */
70+ $ iss = $ payload ['iss ' ];
7071
7172 if (!isset ($ issuers [$ iss ])) {
7273 error_log ("commands.verifyCommandToken: unknown issuer - $ iss " );
@@ -81,7 +82,9 @@ public function verifyCommandToken(string $commandToken): array|false
8182 ]
8283 ]);
8384
84- return json_decode ($ response ->getBody ()->getContents (), true );
85+ /** @var array<string, mixed> $decodedResponse */
86+ $ decodedResponse = json_decode ($ response ->getBody ()->getContents (), true );
87+ return $ decodedResponse ;
8588 } catch (RequestException $ e ) {
8689 error_log ('error verifying command token: ' . $ e ->getMessage ());
8790 return false ;
@@ -116,7 +119,9 @@ public function handleCommand(): string
116119 $ this ->helloResponse ->send ();
117120 }
118121
119- $ commandToken = (string ) $ this ->helloRequest ->fetch ('command_token ' ) ?? '' ;
122+ /** @var string $commandToken */
123+ $ commandToken = $ this ->helloRequest ->fetch ('command_token ' );
124+ /** @var array<string, mixed> $claims */
120125 $ claims = $ this ->verifyCommandToken ($ commandToken );
121126 // Ensure claims is an array before accessing its keys
122127 if (!$ claims || !is_array ($ claims )) {
@@ -129,18 +134,28 @@ public function handleCommand(): string
129134 $ this ->helloResponse ->send ();
130135 }
131136
132- $ command = CommandEnum::tryFrom ((string ) $ claims ['command ' ]) ?? '' ;
137+ /** @var string $commandEnum */
138+ $ commandEnum = $ claims ['command ' ];
139+ $ command = CommandEnum::tryFrom ($ commandEnum ) ?? '' ;
133140 if (!$ command ) {
134141 $ this ->helloResponse ->setStatusCode (400 );
135142 return $ this ->helloResponse ->json (['error ' => 'unsupported_command ' ]);
136143 }
137144
145+ /** @var string $iss */
146+ $ iss = $ claims ['iss ' ];
147+ /** @var string $sub */
148+ $ sub = $ claims ['sub ' ];
149+ /** @var string|null $tenant */
150+ $ tenant = isset ($ claims ['tenant ' ]) ? $ claims ['tenant ' ] : null ;
151+ /** @var array<string>|null $groups */
152+ $ groups = isset ($ claims ['groups ' ]) ? $ claims ['groups ' ] : null ;
138153 $ commandClaims = new CommandClaims (
139- iss: ( string ) $ claims [ ' iss ' ] ,
140- sub: ( string ) $ claims [ ' sub ' ] ,
154+ iss: $ iss ,
155+ sub: $ sub ,
141156 command: $ command ,
142- tenant: isset ( $ claims [ ' tenant ' ]) ? ( string ) $ claims [ ' tenant ' ] : null ,
143- groups: isset ( $ claims [ ' groups ' ]) ? ( array ) $ claims [ ' groups ' ] : null
157+ tenant: $ tenant ,
158+ groups: $ groups
144159 );
145160
146161 $ handler = $ this ->config ->getCommandHandler ();
0 commit comments