Skip to content

Commit f654f6f

Browse files
committed
improved code according to PHPStan reports
1 parent 3884487 commit f654f6f

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,31 +2305,6 @@ parameters:
23052305
count: 1
23062306
path: src/lib/Schema/Worker.php
23072307

2308-
-
2309-
message: "#^Access to an undefined property GraphQL\\\\Language\\\\AST\\\\BooleanValueNode\\|GraphQL\\\\Language\\\\AST\\\\EnumValueNode\\|GraphQL\\\\Language\\\\AST\\\\FloatValueNode\\|GraphQL\\\\Language\\\\AST\\\\IntValueNode\\|GraphQL\\\\Language\\\\AST\\\\ListValueNode\\|GraphQL\\\\Language\\\\AST\\\\NullValueNode\\|GraphQL\\\\Language\\\\AST\\\\ObjectValueNode\\|GraphQL\\\\Language\\\\AST\\\\StringValueNode\\|GraphQL\\\\Language\\\\AST\\\\VariableNode\\:\\:\\$value\\.$#"
2310-
count: 1
2311-
path: src/lib/Security/JWTAuthenticator.php
2312-
2313-
-
2314-
message: "#^Parameter \\#1 \\$user of method Lexik\\\\Bundle\\\\JWTAuthenticationBundle\\\\Services\\\\JWTTokenManagerInterface\\:\\:create\\(\\) expects Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface, Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\|null given\\.$#"
2315-
count: 1
2316-
path: src/lib/Security/JWTAuthenticator.php
2317-
2318-
-
2319-
message: "#^Cannot call method getContent\\(\\) on Symfony\\\\Component\\\\HttpFoundation\\\\Response\\|null\\.$#"
2320-
count: 1
2321-
path: src/lib/Security/JWTTokenMutationFormatEventSubscriber.php
2322-
2323-
-
2324-
message: "#^Cannot call method setContent\\(\\) on Symfony\\\\Component\\\\HttpFoundation\\\\Response\\|null\\.$#"
2325-
count: 1
2326-
path: src/lib/Security/JWTTokenMutationFormatEventSubscriber.php
2327-
2328-
-
2329-
message: "#^Method Ibexa\\\\GraphQL\\\\Security\\\\JWTTokenMutationFormatEventSubscriber\\:\\:formatMutationResponseData\\(\\) should return string but returns string\\|false\\.$#"
2330-
count: 1
2331-
path: src/lib/Security/JWTTokenMutationFormatEventSubscriber.php
2332-
23332308
-
23342309
message: "#^Cannot cast object to string\\.$#"
23352310
count: 1

src/lib/Security/JWTAuthenticator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ public function authenticate(Request $request): Passport
8585
*/
8686
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
8787
{
88+
$user = $token->getUser();
89+
if ($user === null) {
90+
throw new AuthenticationException('No authenticated user found.', 401);
91+
}
92+
8893
return new Response(
8994
json_encode(
9095
[
91-
'token' => $this->tokenManager->create($token->getUser()),
96+
'token' => $this->tokenManager->create($user),
9297
'message' => null,
9398
],
9499
JSON_THROW_ON_ERROR
@@ -131,7 +136,10 @@ private function extractCredentials(string $graphqlQuery): array
131136
$parsed,
132137
[
133138
NodeKind::ARGUMENT => static function (ArgumentNode $node) use (&$credentials): void {
134-
$credentials[$node->name->value] = (string)$node->value->value;
139+
/** @var \GraphQL\Language\AST\StringValueNode $nodeValue */
140+
$nodeValue = $node->value;
141+
142+
$credentials[$node->name->value] = $nodeValue->value;
135143
},
136144
]
137145
);

src/lib/Security/JWTTokenMutationFormatEventSubscriber.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public static function getSubscribedEvents(): array
3131
public function onAuthorizationFinishes(LoginSuccessEvent|LoginFailureEvent $event): void
3232
{
3333
$response = $event->getResponse();
34+
if ($response === null) {
35+
return;
36+
}
37+
3438
$response->setContent(
3539
$this->formatMutationResponseData($response->getContent())
3640
);
@@ -41,10 +45,12 @@ public function onAuthorizationFinishes(LoginSuccessEvent|LoginFailureEvent $eve
4145
*/
4246
private function formatMutationResponseData(mixed $data): string
4347
{
44-
return json_encode([
48+
$formatted = json_encode([
4549
'data' => [
4650
'CreateToken' => json_decode($data, true, 512, JSON_THROW_ON_ERROR),
4751
],
4852
]);
53+
54+
return $formatted === false ? '' : $formatted;
4955
}
5056
}

0 commit comments

Comments
 (0)