Skip to content

[Security][Http] Add type-hints #32314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Security/Http/AccessMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ public function __construct(RequestStack $requestStack)
}

/**
* @param bool $clearSession
*
* @return AuthenticationException|null
*/
public function getLastAuthenticationError($clearSession = true)
public function getLastAuthenticationError(bool $clearSession = true)
{
$request = $this->getRequest();
$authenticationException = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ public function getProviderKey()
return $this->providerKey;
}

/**
* Set the provider key.
*
* @param string $providerKey
*/
public function setProviderKey($providerKey)
public function setProviderKey(string $providerKey)
{
$this->providerKey = $providerKey;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Security/Http/HttpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator = null, $urlMatc
*
* @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 = '/';
Expand All @@ -78,7 +78,7 @@ public function createRedirectResponse(Request $request, $path, $status = 302)
*
* @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());

Expand Down Expand Up @@ -116,7 +116,7 @@ public function createRequest(Request $request, $path)
*
* @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 {
Expand Down Expand Up @@ -147,7 +147,7 @@ public function checkRequestPath(Request $request, $path)
*
* @throws \LogicException
*/
public function generateUri(Request $request, $path)
public function generateUri(Request $request, string $path)
{
if (0 === strpos($path, 'http') || !$path) {
return $path;
Expand Down
14 changes: 3 additions & 11 deletions src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,24 @@ public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter
/**
* 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);
}

/**
* 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];
}
Expand Down
10 changes: 2 additions & 8 deletions src/Symfony/Component/Security/Http/ParameterBagUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ final class ParameterBagUtils
*
* Paths like foo[bar] will be evaluated to find deeper items in nested data structures.
*
* @param ParameterBag $parameters The parameter bag
* @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);
Expand Down Expand Up @@ -64,14 +61,11 @@ public static function getParameterBagValue(ParameterBag $parameters, $path)
*
* Paths like foo[bar] will be evaluated to find deeper items in nested data structures.
*
* @param Request $request The request
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,9 @@ final protected function getUserProvider($class)
/**
* 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
/**
* 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
Expand All @@ -113,14 +111,12 @@ protected function generateCookieValue($class, $username, $expires, $password)
/**
* 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());
}
Expand Down