Skip to content

Commit ceeaa68

Browse files
committed
[Security][Http] Add type-hints
1 parent 8fb4741 commit ceeaa68

File tree

9 files changed

+18
-31
lines changed

9 files changed

+18
-31
lines changed

src/Symfony/Component/Security/Http/AccessMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AccessMap implements AccessMapInterface
2929
* @param array $attributes An array of attributes to pass to the access decision manager (like roles)
3030
* @param string|null $channel The channel to enforce (http, https, or null)
3131
*/
32-
public function add(RequestMatcherInterface $requestMatcher, array $attributes = [], $channel = null)
32+
public function add(RequestMatcherInterface $requestMatcher, array $attributes = [], string $channel = null)
3333
{
3434
$this->map[] = [$requestMatcher, $attributes, $channel];
3535
}

src/Symfony/Component/Security/Http/Authentication/AuthenticationUtils.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ public function __construct(RequestStack $requestStack)
3131
}
3232

3333
/**
34-
* @param bool $clearSession
35-
*
3634
* @return AuthenticationException|null
3735
*/
38-
public function getLastAuthenticationError($clearSession = true)
36+
public function getLastAuthenticationError(bool $clearSession = true)
3937
{
4038
$request = $this->getRequest();
4139
$session = $request->getSession();

src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ public function getProviderKey()
8484

8585
/**
8686
* Set the provider key.
87-
*
88-
* @param string $providerKey
8987
*/
90-
public function setProviderKey($providerKey)
88+
public function setProviderKey(string $providerKey)
9189
{
9290
$this->providerKey = $providerKey;
9391
}

src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,12 @@ public function __invoke(RequestEvent $event)
110110
/**
111111
* Attempts to switch to another user.
112112
*
113-
* @param Request $request A Request instance
114-
* @param string $username
115-
*
116113
* @return TokenInterface|null The new TokenInterface if successfully switched, null otherwise
117114
*
118115
* @throws \LogicException
119116
* @throws AccessDeniedException
120117
*/
121-
private function attemptSwitchUser(Request $request, $username): ?TokenInterface
118+
private function attemptSwitchUser(Request $request, string $username): ?TokenInterface
122119
{
123120
$token = $this->tokenStorage->getToken();
124121
$originalToken = $this->getOriginalToken($token);

src/Symfony/Component/Security/Http/HttpUtils.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator = null, $urlMatc
6060
*
6161
* @return RedirectResponse A RedirectResponse instance
6262
*/
63-
public function createRedirectResponse(Request $request, $path, $status = 302)
63+
public function createRedirectResponse(Request $request, string $path, int $status = 302)
6464
{
6565
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])) {
6666
$path = '/';
@@ -80,7 +80,7 @@ public function createRedirectResponse(Request $request, $path, $status = 302)
8080
*
8181
* @return Request A Request instance
8282
*/
83-
public function createRequest(Request $request, $path)
83+
public function createRequest(Request $request, string $path)
8484
{
8585
$newRequest = Request::create($this->generateUri($request, $path), 'get', [], $request->cookies->all(), [], $request->server->all());
8686

@@ -119,7 +119,7 @@ public function createRequest(Request $request, $path)
119119
*
120120
* @return bool true if the path is the same as the one from the Request, false otherwise
121121
*/
122-
public function checkRequestPath(Request $request, $path)
122+
public function checkRequestPath(Request $request, string $path)
123123
{
124124
if ('/' !== $path[0]) {
125125
try {
@@ -151,7 +151,7 @@ public function checkRequestPath(Request $request, $path)
151151
*
152152
* @throws \LogicException
153153
*/
154-
public function generateUri($request, $path)
154+
public function generateUri(Request $request, string $path)
155155
{
156156
if (0 === strpos($path, 'http') || !$path) {
157157
return $path;

src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter
6060
*
6161
* @return string The logout path
6262
*/
63-
public function getLogoutPath($key = null)
63+
public function getLogoutPath(string $key = null)
6464
{
6565
return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_PATH);
6666
}
@@ -72,16 +72,12 @@ public function getLogoutPath($key = null)
7272
*
7373
* @return string The logout URL
7474
*/
75-
public function getLogoutUrl($key = null)
75+
public function getLogoutUrl(string $key = null)
7676
{
7777
return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_URL);
7878
}
7979

80-
/**
81-
* @param string|null $key The current firewall key
82-
* @param string|null $context The current firewall context
83-
*/
84-
public function setCurrentFirewall($key, $context = null)
80+
public function setCurrentFirewall(string $key, string $context = null)
8581
{
8682
$this->currentFirewall = [$key, $context];
8783
}
@@ -94,7 +90,7 @@ public function setCurrentFirewall($key, $context = null)
9490
*
9591
* @return string The logout URL
9692
*/
97-
private function generateLogoutUrl($key, $referenceType)
93+
private function generateLogoutUrl(string $key, $referenceType)
9894
{
9995
list($logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager) = $this->getListener($key);
10096

@@ -134,7 +130,7 @@ private function generateLogoutUrl($key, $referenceType)
134130
*
135131
* @throws \InvalidArgumentException if no LogoutListener is registered for the key or could not be found automatically
136132
*/
137-
private function getListener($key)
133+
private function getListener(string $key)
138134
{
139135
if (null !== $key) {
140136
if (isset($this->listeners[$key])) {

src/Symfony/Component/Security/Http/ParameterBagUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class ParameterBagUtils
3636
*
3737
* @throws InvalidArgumentException when the given path is malformed
3838
*/
39-
public static function getParameterBagValue(ParameterBag $parameters, $path)
39+
public static function getParameterBagValue(ParameterBag $parameters, string $path)
4040
{
4141
if (false === $pos = strpos($path, '[')) {
4242
return $parameters->get($path);
@@ -71,7 +71,7 @@ public static function getParameterBagValue(ParameterBag $parameters, $path)
7171
*
7272
* @throws InvalidArgumentException when the given path is malformed
7373
*/
74-
public static function getRequestParameterValue(Request $request, $path)
74+
public static function getRequestParameterValue(Request $request, string $path)
7575
{
7676
if (false === $pos = strpos($path, '[')) {
7777
return $request->get($path);

src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,9 @@ final protected function getUserProvider($class)
235235
/**
236236
* Decodes the raw cookie value.
237237
*
238-
* @param string $rawCookie
239-
*
240238
* @return array
241239
*/
242-
protected function decodeCookie($rawCookie)
240+
protected function decodeCookie(string $rawCookie)
243241
{
244242
return explode(self::COOKIE_DELIMITER, base64_decode($rawCookie));
245243
}

src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
9898
*
9999
* @return string
100100
*/
101-
protected function generateCookieValue($class, $username, $expires, $password)
101+
protected function generateCookieValue(string $class, string $username, int $expires, string $password)
102102
{
103103
// $username is encoded because it might contain COOKIE_DELIMITER,
104104
// we assume other values don't
@@ -120,7 +120,7 @@ protected function generateCookieValue($class, $username, $expires, $password)
120120
*
121121
* @return string
122122
*/
123-
protected function generateCookieHash($class, $username, $expires, $password)
123+
protected function generateCookieHash(string $class, string $username, int $expires, string $password)
124124
{
125125
return hash_hmac('sha256', $class.self::COOKIE_DELIMITER.$username.self::COOKIE_DELIMITER.$expires.self::COOKIE_DELIMITER.$password, $this->getSecret());
126126
}

0 commit comments

Comments
 (0)