Skip to content

Commit 06529a8

Browse files
committed
Add return types to adapter interface
1 parent 9d7d872 commit 06529a8

File tree

3 files changed

+20
-41
lines changed

3 files changed

+20
-41
lines changed

src/Adapter/AdapterInterface.php

+7-26
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,9 @@
1414
use Psr\Http\Message\ResponseInterface;
1515
use Psr\Http\Message\ServerRequestInterface;
1616

17-
/**
18-
* @package ActiveCollab\Authentication\Adapter
19-
*/
2017
interface AdapterInterface
2118
{
22-
/**
23-
* Initialize authentication layer and see if we have a user who's already logged in.
24-
*
25-
* @param ServerRequestInterface $request
26-
* @return TransportInterface
27-
*/
28-
public function initialize(ServerRequestInterface $request);
19+
public function initialize(ServerRequestInterface $request): ?TransportInterface;
2920

3021
public function applyToRequest(
3122
ServerRequestInterface $request,
@@ -43,20 +34,10 @@ public function applyTo(
4334
TransportInterface $transport
4435
): array;
4536

46-
/**
47-
* Authenticate user against authentication source.
48-
*
49-
* @param AuthenticatedUserInterface $authenticated_user
50-
* @param array $credentials
51-
* @return AuthenticationResultInterface
52-
*/
53-
public function authenticate(AuthenticatedUserInterface $authenticated_user, array $credentials = []);
54-
55-
/**
56-
* Terminate an instance that was used to authenticate a user.
57-
*
58-
* @param AuthenticationResultInterface $authenticated_with
59-
* @return TransportInterface
60-
*/
61-
public function terminate(AuthenticationResultInterface $authenticated_with);
37+
public function authenticate(
38+
AuthenticatedUserInterface $authenticated_user,
39+
array $credentials = []
40+
): AuthenticationResultInterface;
41+
42+
public function terminate(AuthenticationResultInterface $authenticated_with): TransportInterface;
6243
}

src/Adapter/BrowserSessionAdapter.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
$this->session_cookie_name = $session_cookie_name;
5454
}
5555

56-
public function initialize(ServerRequestInterface $request)
56+
public function initialize(ServerRequestInterface $request): ?TransportInterface
5757
{
5858
$session_id = $this->cookies->get($request, $this->session_cookie_name);
5959

@@ -128,12 +128,15 @@ public function applyToResponse(ResponseInterface $response, TransportInterface
128128
return $response;
129129
}
130130

131-
public function authenticate(AuthenticatedUserInterface $authenticated_user, array $credentials = [])
131+
public function authenticate(
132+
AuthenticatedUserInterface $authenticated_user,
133+
array $credentials = []
134+
): AuthenticationResultInterface
132135
{
133136
return $this->session_repository->createSession($authenticated_user, $credentials);
134137
}
135138

136-
public function terminate(AuthenticationResultInterface $authenticated_with)
139+
public function terminate(AuthenticationResultInterface $authenticated_with): TransportInterface
137140
{
138141
if (!$authenticated_with instanceof SessionInterface) {
139142
throw new InvalidArgumentException('Instance is not a browser session');

src/Adapter/TokenBearerAdapter.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ActiveCollab\Authentication\AuthenticationResult\AuthenticationResultInterface;
1616
use ActiveCollab\Authentication\AuthenticationResult\Transport\Authentication\AuthenticationTransport;
1717
use ActiveCollab\Authentication\AuthenticationResult\Transport\Deauthentication\DeauthenticationTransport;
18+
use ActiveCollab\Authentication\AuthenticationResult\Transport\TransportInterface;
1819
use ActiveCollab\Authentication\Exception\InvalidTokenException;
1920
use ActiveCollab\Authentication\Token\RepositoryInterface as TokenRepositoryInterface;
2021
use ActiveCollab\Authentication\Token\TokenInterface;
@@ -35,10 +36,7 @@ public function __construct(
3536
$this->token_repository = $token_repository;
3637
}
3738

38-
/**
39-
* {@inheritdoc}
40-
*/
41-
public function initialize(ServerRequestInterface $request)
39+
public function initialize(ServerRequestInterface $request): ?TransportInterface
4240
{
4341
if (!$request->hasHeader('Authorization')) {
4442
return null;
@@ -67,18 +65,15 @@ public function initialize(ServerRequestInterface $request)
6765
throw new InvalidTokenException();
6866
}
6967

70-
/**
71-
* {@inheritdoc}
72-
*/
73-
public function authenticate(AuthenticatedUserInterface $authenticated_user, array $credentials = [])
68+
public function authenticate(
69+
AuthenticatedUserInterface $authenticated_user,
70+
array $credentials = []
71+
): AuthenticationResultInterface
7472
{
7573
return $this->token_repository->issueToken($authenticated_user, $credentials);
7674
}
7775

78-
/**
79-
* {@inheritdoc}
80-
*/
81-
public function terminate(AuthenticationResultInterface $authenticated_with)
76+
public function terminate(AuthenticationResultInterface $authenticated_with): TransportInterface
8277
{
8378
if (!$authenticated_with instanceof TokenInterface) {
8479
throw new InvalidArgumentException('Instance is not a token');

0 commit comments

Comments
 (0)