From 6bae9bc0e5aefa8f5311af6e28264fdab32cb063 Mon Sep 17 00:00:00 2001 From: Andreia Bohner Date: Tue, 2 Jul 2019 00:07:06 -0300 Subject: [PATCH] [Security][Http] Add type-hints --- src/Symfony/Component/Security/Http/AccessMap.php | 2 +- .../Http/Authentication/AuthenticationUtils.php | 4 +--- .../DefaultAuthenticationSuccessHandler.php | 7 +------ src/Symfony/Component/Security/Http/HttpUtils.php | 8 ++++---- .../Security/Http/Logout/LogoutUrlGenerator.php | 14 +++----------- .../Component/Security/Http/ParameterBagUtils.php | 8 ++------ .../Http/RememberMe/AbstractRememberMeServices.php | 4 +--- .../RememberMe/TokenBasedRememberMeServices.php | 8 ++------ 8 files changed, 15 insertions(+), 40 deletions(-) diff --git a/src/Symfony/Component/Security/Http/AccessMap.php b/src/Symfony/Component/Security/Http/AccessMap.php index 1a64f2dace..f87283f334 100644 --- a/src/Symfony/Component/Security/Http/AccessMap.php +++ b/src/Symfony/Component/Security/Http/AccessMap.php @@ -28,7 +28,7 @@ class AccessMap implements AccessMapInterface * @param array $attributes An array of attributes to pass to the access decision manager (like roles) * @param string|null $channel The channel to enforce (http, https, or null) */ - public function add(RequestMatcherInterface $requestMatcher, array $attributes = [], $channel = null) + public function add(RequestMatcherInterface $requestMatcher, array $attributes = [], string $channel = null) { $this->map[] = [$requestMatcher, $attributes, $channel]; } diff --git a/src/Symfony/Component/Security/Http/Authentication/AuthenticationUtils.php b/src/Symfony/Component/Security/Http/Authentication/AuthenticationUtils.php index af7e4919c3..c7d6bfe486 100644 --- a/src/Symfony/Component/Security/Http/Authentication/AuthenticationUtils.php +++ b/src/Symfony/Component/Security/Http/Authentication/AuthenticationUtils.php @@ -31,11 +31,9 @@ class AuthenticationUtils } /** - * @param bool $clearSession - * * @return AuthenticationException|null */ - public function getLastAuthenticationError($clearSession = true) + public function getLastAuthenticationError(bool $clearSession = true) { $request = $this->getRequest(); $authenticationException = null; diff --git a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php index f0580320f4..9923ec66af 100644 --- a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php +++ b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php @@ -81,12 +81,7 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle return $this->providerKey; } - /** - * Set the provider key. - * - * @param string $providerKey - */ - public function setProviderKey($providerKey) + public function setProviderKey(string $providerKey) { $this->providerKey = $providerKey; } diff --git a/src/Symfony/Component/Security/Http/HttpUtils.php b/src/Symfony/Component/Security/Http/HttpUtils.php index 732202c68f..70416b6e42 100644 --- a/src/Symfony/Component/Security/Http/HttpUtils.php +++ b/src/Symfony/Component/Security/Http/HttpUtils.php @@ -58,7 +58,7 @@ class HttpUtils * * @return RedirectResponse A RedirectResponse instance */ - public function createRedirectResponse(Request $request, $path, $status = 302) + public function createRedirectResponse(Request $request, string $path, int $status = 302) { 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])) { $path = '/'; @@ -77,7 +77,7 @@ class HttpUtils * * @return Request A Request instance */ - public function createRequest(Request $request, $path) + public function createRequest(Request $request, string $path) { $newRequest = Request::create($this->generateUri($request, $path), 'get', [], $request->cookies->all(), [], $request->server->all()); @@ -115,7 +115,7 @@ class HttpUtils * * @return bool true if the path is the same as the one from the Request, false otherwise */ - public function checkRequestPath(Request $request, $path) + public function checkRequestPath(Request $request, string $path) { if ('/' !== $path[0]) { try { @@ -146,7 +146,7 @@ class HttpUtils * * @throws \LogicException */ - public function generateUri(Request $request, $path) + public function generateUri(Request $request, string $path) { if (0 === strpos($path, 'http') || !$path) { return $path; diff --git a/src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php b/src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php index f66f558ebe..f977064aab 100644 --- a/src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php +++ b/src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php @@ -55,11 +55,9 @@ class LogoutUrlGenerator /** * Generates the absolute logout path for the firewall. * - * @param string|null $key The firewall key or null to use the current firewall key - * * @return string The logout path */ - public function getLogoutPath($key = null) + public function getLogoutPath(string $key = null) { return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_PATH); } @@ -67,20 +65,14 @@ class LogoutUrlGenerator /** * Generates the absolute logout URL for the firewall. * - * @param string|null $key The firewall key or null to use the current firewall key - * * @return string The logout URL */ - public function getLogoutUrl($key = null) + public function getLogoutUrl(string $key = null) { return $this->generateLogoutUrl($key, UrlGeneratorInterface::ABSOLUTE_URL); } - /** - * @param string|null $key The current firewall key - * @param string|null $context The current firewall context - */ - public function setCurrentFirewall($key, $context = null) + public function setCurrentFirewall(?string $key, string $context = null) { $this->currentFirewall = [$key, $context]; } diff --git a/src/Symfony/Component/Security/Http/ParameterBagUtils.php b/src/Symfony/Component/Security/Http/ParameterBagUtils.php index c303384418..e426b9b3f8 100644 --- a/src/Symfony/Component/Security/Http/ParameterBagUtils.php +++ b/src/Symfony/Component/Security/Http/ParameterBagUtils.php @@ -29,13 +29,11 @@ final class ParameterBagUtils * * Paths like foo[bar] will be evaluated to find deeper items in nested data structures. * - * @param string $path The key - * * @return mixed * * @throws InvalidArgumentException when the given path is malformed */ - public static function getParameterBagValue(ParameterBag $parameters, $path) + public static function getParameterBagValue(ParameterBag $parameters, string $path) { if (false === $pos = strpos($path, '[')) { return $parameters->get($path); @@ -63,13 +61,11 @@ final class ParameterBagUtils * * Paths like foo[bar] will be evaluated to find deeper items in nested data structures. * - * @param string $path The key - * * @return mixed * * @throws InvalidArgumentException when the given path is malformed */ - public static function getRequestParameterValue(Request $request, $path) + public static function getRequestParameterValue(Request $request, string $path) { if (false === $pos = strpos($path, '[')) { return $request->get($path); diff --git a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php index cf98bc7766..0555d33b52 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php @@ -235,11 +235,9 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface /** * Decodes the raw cookie value. * - * @param string $rawCookie - * * @return array */ - protected function decodeCookie($rawCookie) + protected function decodeCookie(string $rawCookie) { return explode(self::COOKIE_DELIMITER, base64_decode($rawCookie)); } diff --git a/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php index 26901c2439..f11e1dc02f 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php @@ -91,14 +91,12 @@ class TokenBasedRememberMeServices extends AbstractRememberMeServices /** * Generates the cookie value. * - * @param string $class - * @param string $username The username * @param int $expires The Unix timestamp when the cookie expires * @param string $password The encoded password * * @return string */ - protected function generateCookieValue($class, $username, $expires, $password) + protected function generateCookieValue(string $class, string $username, int $expires, string $password) { // $username is encoded because it might contain COOKIE_DELIMITER, // we assume other values don't @@ -113,14 +111,12 @@ class TokenBasedRememberMeServices extends AbstractRememberMeServices /** * Generates a hash for the cookie to ensure it is not being tampered with. * - * @param string $class - * @param string $username The username * @param int $expires The Unix timestamp when the cookie expires * @param string $password The encoded password * * @return string */ - protected function generateCookieHash($class, $username, $expires, $password) + protected function generateCookieHash(string $class, string $username, int $expires, string $password) { return hash_hmac('sha256', $class.self::COOKIE_DELIMITER.$username.self::COOKIE_DELIMITER.$expires.self::COOKIE_DELIMITER.$password, $this->getSecret()); }