Skip to content

Commit 8da9fc1

Browse files
[Security] add return types
1 parent cbac592 commit 8da9fc1

27 files changed

+36
-81
lines changed

AccessMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function add(RequestMatcherInterface $requestMatcher, array $attributes =
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function getPatterns(Request $request)
39+
public function getPatterns(Request $request): array
4040
{
4141
foreach ($this->map as $elements) {
4242
if (null === $elements[0] || $elements[0]->matches($request)) {

AccessMapInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ interface AccessMapInterface
2727
*
2828
* @return array{0: array|null, 1: string|null} A tuple of security attributes and the required channel
2929
*/
30-
public function getPatterns(Request $request);
30+
public function getPatterns(Request $request): array;
3131
}

Authentication/AuthenticationFailureHandlerInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ interface AuthenticationFailureHandlerInterface
3030
* This is called when an interactive authentication attempt fails. This is
3131
* called by authentication listeners inheriting from
3232
* AbstractAuthenticationListener.
33-
*
34-
* @return Response
3533
*/
36-
public function onAuthenticationFailure(Request $request, AuthenticationException $exception);
34+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response;
3735
}

Authentication/AuthenticationSuccessHandlerInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ interface AuthenticationSuccessHandlerInterface
3030
* This is called when an interactive authentication attempt succeeds. This
3131
* is called by authentication listeners inheriting from
3232
* AbstractAuthenticationListener.
33-
*
34-
* @return Response
3533
*/
36-
public function onAuthenticationSuccess(Request $request, TokenInterface $token);
34+
public function onAuthenticationSuccess(Request $request, TokenInterface $token): Response;
3735
}

Authentication/AuthenticationUtils.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ public function __construct(RequestStack $requestStack)
3030
$this->requestStack = $requestStack;
3131
}
3232

33-
/**
34-
* @return AuthenticationException|null
35-
*/
36-
public function getLastAuthenticationError(bool $clearSession = true)
33+
public function getLastAuthenticationError(bool $clearSession = true): ?AuthenticationException
3734
{
3835
$request = $this->getRequest();
3936
$authenticationException = null;
@@ -51,10 +48,7 @@ public function getLastAuthenticationError(bool $clearSession = true)
5148
return $authenticationException;
5249
}
5350

54-
/**
55-
* @return string
56-
*/
57-
public function getLastUsername()
51+
public function getLastUsername(): string
5852
{
5953
$request = $this->getRequest();
6054

Authentication/CustomAuthenticationFailureHandler.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Authentication;
1313

1414
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
1516
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1617

1718
/**
@@ -35,7 +36,7 @@ public function __construct(AuthenticationFailureHandlerInterface $handler, arra
3536
/**
3637
* {@inheritdoc}
3738
*/
38-
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
39+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response
3940
{
4041
return $this->handler->onAuthenticationFailure($request, $exception);
4142
}

Authentication/CustomAuthenticationSuccessHandler.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Authentication;
1313

1414
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
1516
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1617

1718
/**
@@ -39,7 +40,7 @@ public function __construct(AuthenticationSuccessHandlerInterface $handler, arra
3940
/**
4041
* {@inheritdoc}
4142
*/
42-
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
43+
public function onAuthenticationSuccess(Request $request, TokenInterface $token): Response
4344
{
4445
return $this->handler->onAuthenticationSuccess($request, $token);
4546
}

Authentication/DefaultAuthenticationFailureHandler.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Psr\Log\LoggerInterface;
1515
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Response;
1617
use Symfony\Component\HttpKernel\HttpKernelInterface;
1718
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1819
use Symfony\Component\Security\Core\Security;
@@ -52,10 +53,8 @@ public function __construct(HttpKernelInterface $httpKernel, HttpUtils $httpUtil
5253

5354
/**
5455
* Gets the options.
55-
*
56-
* @return array
5756
*/
58-
public function getOptions()
57+
public function getOptions(): array
5958
{
6059
return $this->options;
6160
}
@@ -68,7 +67,7 @@ public function setOptions(array $options)
6867
/**
6968
* {@inheritdoc}
7069
*/
71-
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
70+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response
7271
{
7372
if ($failureUrl = ParameterBagUtils::getRequestParameterValue($request, $this->options['failure_path_parameter'])) {
7473
$this->options['failure_path'] = $failureUrl;

Authentication/DefaultAuthenticationSuccessHandler.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Authentication;
1313

1414
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
1516
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1617
use Symfony\Component\Security\Http\HttpUtils;
1718
use Symfony\Component\Security\Http\ParameterBagUtils;
@@ -51,17 +52,15 @@ public function __construct(HttpUtils $httpUtils, array $options = [])
5152
/**
5253
* {@inheritdoc}
5354
*/
54-
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
55+
public function onAuthenticationSuccess(Request $request, TokenInterface $token): Response
5556
{
5657
return $this->httpUtils->createRedirectResponse($request, $this->determineTargetUrl($request));
5758
}
5859

5960
/**
6061
* Gets the options.
61-
*
62-
* @return array
6362
*/
64-
public function getOptions()
63+
public function getOptions(): array
6564
{
6665
return $this->options;
6766
}
@@ -83,10 +82,8 @@ public function setFirewallName(string $firewallName): void
8382

8483
/**
8584
* Builds the target URL according to the defined options.
86-
*
87-
* @return string
8885
*/
89-
protected function determineTargetUrl(Request $request)
86+
protected function determineTargetUrl(Request $request): string
9087
{
9188
if ($this->options['always_use_default_target_path']) {
9289
return $this->options['default_target_path'];

Authenticator/AbstractAuthenticator.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Security\Http\Authenticator;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15-
use Symfony\Component\Security\Core\Exception\LogicException;
1615
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
1716
use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;
1817

Authenticator/Passport/Badge/RememberMeBadge.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RememberMeBadge implements BadgeInterface
3737
*
3838
* @return $this
3939
*/
40-
public function enable(): self
40+
public function enable(): static
4141
{
4242
$this->enabled = true;
4343

@@ -52,7 +52,7 @@ public function enable(): self
5252
*
5353
* @return $this
5454
*/
55-
public function disable(): self
55+
public function disable(): static
5656
{
5757
$this->enabled = false;
5858

Authenticator/Passport/Passport.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ public function __construct(UserBadge $userBadge, CredentialsInterface $credenti
4242
}
4343
}
4444

45-
/**
46-
* {@inheritdoc}
47-
*/
4845
public function getUser(): UserInterface
4946
{
5047
if (null === $this->user) {
@@ -88,10 +85,7 @@ public function setAttribute(string $name, mixed $value): void
8885
$this->attributes[$name] = $value;
8986
}
9087

91-
/**
92-
* @return mixed
93-
*/
94-
public function getAttribute(string $name, mixed $default = null)
88+
public function getAttribute(string $name, mixed $default = null): mixed
9589
{
9690
return $this->attributes[$name] ?? $default;
9791
}

Authenticator/Token/PostAuthenticationToken.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(UserInterface $user, string $firewallName, array $ro
4747
*
4848
* {@inheritdoc}
4949
*/
50-
public function getCredentials()
50+
public function getCredentials(): mixed
5151
{
5252
return [];
5353
}

Authorization/AccessDeniedHandlerInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ interface AccessDeniedHandlerInterface
2525
{
2626
/**
2727
* Handles an access denied failure.
28-
*
29-
* @return Response|null
3028
*/
31-
public function handle(Request $request, AccessDeniedException $accessDeniedException);
29+
public function handle(Request $request, AccessDeniedException $accessDeniedException): ?Response;
3230
}

Event/LoginSuccessEvent.php

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17-
use Symfony\Component\Security\Core\Exception\LogicException;
1817
use Symfony\Component\Security\Core\User\UserInterface;
1918
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
2019
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;

Firewall/AccessListener.php

-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpKernel\Event\RequestEvent;
16-
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
1716
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
1817
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1918
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
2019
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2120
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
22-
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
2321
use Symfony\Component\Security\Http\AccessMapInterface;
24-
use Symfony\Component\Security\Http\Authentication\NoopAuthenticationManager;
2522
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
2623

2724
/**

Firewall/ChannelListener.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpKernel\Event\RequestEvent;
1818
use Symfony\Component\Security\Http\AccessMapInterface;
19-
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2019

2120
/**
2221
* ChannelListener switches the HTTP protocol based on the access control

Firewall/ContextListener.php

-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
3030
use Symfony\Component\Security\Core\User\UserInterface;
3131
use Symfony\Component\Security\Core\User\UserProviderInterface;
32-
use Symfony\Component\Security\Http\Event\DeauthenticatedEvent;
3332
use Symfony\Component\Security\Http\Event\TokenDeauthenticatedEvent;
3433
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
3534

@@ -299,9 +298,6 @@ private function safelyUnserialize(string $serializedToken)
299298
return $token;
300299
}
301300

302-
/**
303-
* @param UserInterface $originalUser
304-
*/
305301
private static function hasUserChanged(UserInterface $originalUser, TokenInterface $refreshedToken): bool
306302
{
307303
$refreshedUser = $refreshedToken->getUser();

FirewallMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function add(RequestMatcherInterface $requestMatcher = null, array $liste
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function getListeners(Request $request)
37+
public function getListeners(Request $request): array
3838
{
3939
foreach ($this->map as $elements) {
4040
if (null === $elements[0] || $elements[0]->matches($request)) {

HttpUtils.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ public function __construct(UrlGeneratorInterface $urlGenerator = null, UrlMatch
5151
*
5252
* @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
5353
* @param int $status The status code
54-
*
55-
* @return RedirectResponse
5654
*/
57-
public function createRedirectResponse(Request $request, string $path, int $status = 302)
55+
public function createRedirectResponse(Request $request, string $path, int $status = 302): RedirectResponse
5856
{
5957
if (null !== $this->secureDomainRegexp && 'https' === $this->urlMatcher->getContext()->getScheme() && preg_match('#^https?:[/\\\\]{2,}+[^/]++#i', $path, $host) && !preg_match(sprintf($this->secureDomainRegexp, preg_quote($request->getHttpHost())), $host[0])) {
6058
$path = '/';
@@ -70,10 +68,8 @@ public function createRedirectResponse(Request $request, string $path, int $stat
7068
* Creates a Request.
7169
*
7270
* @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
73-
*
74-
* @return Request
7571
*/
76-
public function createRequest(Request $request, string $path)
72+
public function createRequest(Request $request, string $path): Request
7773
{
7874
$newRequest = Request::create($this->generateUri($request, $path), 'get', [], $request->cookies->all(), [], $request->server->all());
7975

@@ -111,7 +107,7 @@ public function createRequest(Request $request, string $path)
111107
*
112108
* @return bool true if the path is the same as the one from the Request, false otherwise
113109
*/
114-
public function checkRequestPath(Request $request, string $path)
110+
public function checkRequestPath(Request $request, string $path): bool
115111
{
116112
if ('/' !== $path[0]) {
117113
try {
@@ -138,11 +134,9 @@ public function checkRequestPath(Request $request, string $path)
138134
*
139135
* @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
140136
*
141-
* @return string
142-
*
143137
* @throws \LogicException
144138
*/
145-
public function generateUri(Request $request, string $path)
139+
public function generateUri(Request $request, string $path): string
146140
{
147141
if (str_starts_with($path, 'http') || !$path) {
148142
return $path;

LoginLink/Exception/InvalidLoginLinkAuthenticationException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class InvalidLoginLinkAuthenticationException extends AuthenticationException
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function getMessageKey()
26+
public function getMessageKey(): string
2727
{
2828
return 'Invalid or expired login link.';
2929
}

Logout/LogoutUrlGenerator.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,16 @@ public function registerListener(string $key, string $logoutPath, ?string $csrfT
5353

5454
/**
5555
* Generates the absolute logout path for the firewall.
56-
*
57-
* @return string
5856
*/
59-
public function getLogoutPath(string $key = null)
57+
public function getLogoutPath(string $key = null): string
6058
{
6159
return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_PATH);
6260
}
6361

6462
/**
6563
* Generates the absolute logout URL for the firewall.
66-
*
67-
* @return string
6864
*/
69-
public function getLogoutUrl(string $key = null)
65+
public function getLogoutUrl(string $key = null): string
7066
{
7167
return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_URL);
7268
}

0 commit comments

Comments
 (0)