Skip to content

Commit 73e4ce2

Browse files
authored
Merge pull request #78 from samsonasik/update-to-use-php81-syntax
Update to use PHP 8.1 syntax
2 parents 86fd62a + 389965c commit 73e4ce2

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

src/AuthorizationHandler.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@
2525
*/
2626
class AuthorizationHandler implements RequestHandlerInterface
2727
{
28-
private AuthorizationServer $server;
29-
30-
private ResponseFactoryInterface $responseFactory;
28+
private readonly ResponseFactoryInterface $responseFactory;
3129

3230
/**
3331
* @param (callable():ResponseInterface)|ResponseFactoryInterface $responseFactory
3432
*/
35-
public function __construct(AuthorizationServer $server, $responseFactory)
33+
public function __construct(private readonly AuthorizationServer $server, $responseFactory)
3634
{
37-
$this->server = $server;
3835
if (is_callable($responseFactory)) {
3936
$responseFactory = new CallableResponseFactoryDecorator(
4037
static fn(): ResponseInterface => $responseFactory()

src/OAuth2Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function authenticate(ServerRequestInterface $request): ?UserInterface
6868
]
6969
);
7070
}
71-
} catch (OAuthServerException $exception) {
71+
} catch (OAuthServerException) {
7272
return null;
7373
}
7474
return null;

src/Repository/Pdo/ClientRepository.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,12 @@ public function validateClient($clientIdentifier, $clientSecret, $grantType): bo
6060
*/
6161
protected function isGranted(array $row, ?string $grantType = null): bool
6262
{
63-
switch ($grantType) {
64-
case 'authorization_code':
65-
return ! ($row['personal_access_client'] || $row['password_client']);
66-
case 'personal_access':
67-
return (bool) $row['personal_access_client'];
68-
case 'password':
69-
return (bool) $row['password_client'];
70-
default:
71-
return true;
72-
}
63+
return match ($grantType) {
64+
'authorization_code' => ! ($row['personal_access_client'] || $row['password_client']),
65+
'personal_access' => (bool) $row['personal_access_client'],
66+
'password' => (bool) $row['password_client'],
67+
default => true,
68+
};
7369
}
7470

7571
private function getClientData(string $clientIdentifier): ?array

test/Pdo/OAuth2PdoMiddlewareTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,8 @@ private function buildConsumerAuthMiddleware(AuthorizationHandler $authHandler):
492492
{
493493
return new class ($authHandler) implements RequestHandlerInterface
494494
{
495-
private AuthorizationHandler $handler;
496-
497-
public function __construct(AuthorizationHandler $handler)
495+
public function __construct(private readonly AuthorizationHandler $handler)
498496
{
499-
$this->handler = $handler;
500497
}
501498

502499
public function handle(

0 commit comments

Comments
 (0)