[Security][Http] Add type-hints

This commit is contained in:
Andreia Bohner 2019-07-02 00:07:06 -03:00 committed by Nicolas Grekas
parent f6c5848746
commit 6bae9bc0e5
8 changed files with 15 additions and 40 deletions

View File

@ -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];
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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];
}

View File

@ -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);

View File

@ -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));
}

View File

@ -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());
}