Skip to content

Commit 09f861b

Browse files
andreiachalasr
authored andcommitted
[Security][Http] Add type-hints
1 parent 1126fa6 commit 09f861b

File tree

8 files changed

+15
-42
lines changed

8 files changed

+15
-42
lines changed

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

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

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
$authenticationException = null;

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@ public function getProviderKey()
8282
return $this->providerKey;
8383
}
8484

85-
/**
86-
* Set the provider key.
87-
*
88-
* @param string $providerKey
89-
*/
90-
public function setProviderKey($providerKey)
85+
public function setProviderKey(string $providerKey)
9186
{
9287
$this->providerKey = $providerKey;
9388
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator = null, $urlMatc
5858
*
5959
* @return RedirectResponse A RedirectResponse instance
6060
*/
61-
public function createRedirectResponse(Request $request, $path, $status = 302)
61+
public function createRedirectResponse(Request $request, string $path, int $status = 302)
6262
{
6363
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])) {
6464
$path = '/';
@@ -78,7 +78,7 @@ public function createRedirectResponse(Request $request, $path, $status = 302)
7878
*
7979
* @return Request A Request instance
8080
*/
81-
public function createRequest(Request $request, $path)
81+
public function createRequest(Request $request, string $path)
8282
{
8383
$newRequest = Request::create($this->generateUri($request, $path), 'get', [], $request->cookies->all(), [], $request->server->all());
8484

@@ -116,7 +116,7 @@ public function createRequest(Request $request, $path)
116116
*
117117
* @return bool true if the path is the same as the one from the Request, false otherwise
118118
*/
119-
public function checkRequestPath(Request $request, $path)
119+
public function checkRequestPath(Request $request, string $path)
120120
{
121121
if ('/' !== $path[0]) {
122122
try {
@@ -147,7 +147,7 @@ public function checkRequestPath(Request $request, $path)
147147
*
148148
* @throws \LogicException
149149
*/
150-
public function generateUri(Request $request, $path)
150+
public function generateUri(Request $request, string $path)
151151
{
152152
if (0 === strpos($path, 'http') || !$path) {
153153
return $path;

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,24 @@ public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter
5656
/**
5757
* Generates the absolute logout path for the firewall.
5858
*
59-
* @param string|null $key The firewall key or null to use the current firewall key
60-
*
6159
* @return string The logout path
6260
*/
63-
public function getLogoutPath($key = null)
61+
public function getLogoutPath(string $key = null)
6462
{
6563
return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_PATH);
6664
}
6765

6866
/**
6967
* Generates the absolute logout URL for the firewall.
7068
*
71-
* @param string|null $key The firewall key or null to use the current firewall key
72-
*
7369
* @return string The logout URL
7470
*/
75-
public function getLogoutUrl($key = null)
71+
public function getLogoutUrl(string $key = null)
7672
{
7773
return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_URL);
7874
}
7975

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)
76+
public function setCurrentFirewall(?string $key, string $context = null)
8577
{
8678
$this->currentFirewall = [$key, $context];
8779
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ final class ParameterBagUtils
2929
*
3030
* Paths like foo[bar] will be evaluated to find deeper items in nested data structures.
3131
*
32-
* @param ParameterBag $parameters The parameter bag
33-
* @param string $path The key
34-
*
3532
* @return mixed
3633
*
3734
* @throws InvalidArgumentException when the given path is malformed
3835
*/
39-
public static function getParameterBagValue(ParameterBag $parameters, $path)
36+
public static function getParameterBagValue(ParameterBag $parameters, string $path)
4037
{
4138
if (false === $pos = strpos($path, '[')) {
4239
return $parameters->get($path);
@@ -64,14 +61,11 @@ public static function getParameterBagValue(ParameterBag $parameters, $path)
6461
*
6562
* Paths like foo[bar] will be evaluated to find deeper items in nested data structures.
6663
*
67-
* @param Request $request The request
68-
* @param string $path The key
69-
*
7064
* @return mixed
7165
*
7266
* @throws InvalidArgumentException when the given path is malformed
7367
*/
74-
public static function getRequestParameterValue(Request $request, $path)
68+
public static function getRequestParameterValue(Request $request, string $path)
7569
{
7670
if (false === $pos = strpos($path, '[')) {
7771
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,12 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
9191
/**
9292
* Generates the cookie value.
9393
*
94-
* @param string $class
95-
* @param string $username The username
9694
* @param int $expires The Unix timestamp when the cookie expires
9795
* @param string $password The encoded password
9896
*
9997
* @return string
10098
*/
101-
protected function generateCookieValue($class, $username, $expires, $password)
99+
protected function generateCookieValue(string $class, string $username, int $expires, string $password)
102100
{
103101
// $username is encoded because it might contain COOKIE_DELIMITER,
104102
// we assume other values don't
@@ -113,14 +111,12 @@ protected function generateCookieValue($class, $username, $expires, $password)
113111
/**
114112
* Generates a hash for the cookie to ensure it is not being tampered with.
115113
*
116-
* @param string $class
117-
* @param string $username The username
118114
* @param int $expires The Unix timestamp when the cookie expires
119115
* @param string $password The encoded password
120116
*
121117
* @return string
122118
*/
123-
protected function generateCookieHash($class, $username, $expires, $password)
119+
protected function generateCookieHash(string $class, string $username, int $expires, string $password)
124120
{
125121
return hash_hmac('sha256', $class.self::COOKIE_DELIMITER.$username.self::COOKIE_DELIMITER.$expires.self::COOKIE_DELIMITER.$password, $this->getSecret());
126122
}

0 commit comments

Comments
 (0)