Skip to content

[Security][SecurityBundle] Add types to private properties #43872

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

Merged
merged 1 commit into from
Nov 3, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

class ExpressionCacheWarmer implements CacheWarmerInterface
{
private $expressions;
private $expressionLanguage;
private iterable $expressions;
private ExpressionLanguage $expressionLanguage;

/**
* @param iterable|Expression[] $expressions
* @param iterable<mixed, Expression|string> $expressions
*/
public function __construct(iterable $expressions, ExpressionLanguage $expressionLanguage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
#[AsCommand(name: 'debug:firewall', description: 'Display information about your security firewall(s)')]
final class DebugFirewallCommand extends Command
{
private $firewallNames;
private $contexts;
private $eventDispatchers;
private $authenticators;
private array $firewallNames;
private ContainerInterface $contexts;
private ContainerInterface $eventDispatchers;
private array $authenticators;

/**
* @param string[] $firewallNames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
*/
class SecurityDataCollector extends DataCollector implements LateDataCollectorInterface
{
private $tokenStorage;
private $roleHierarchy;
private $logoutUrlGenerator;
private $accessDecisionManager;
private $firewallMap;
private $firewall;
private $hasVarDumper;
private ?TokenStorageInterface $tokenStorage;
private ?RoleHierarchyInterface $roleHierarchy;
private ?LogoutUrlGenerator $logoutUrlGenerator;
private ?AccessDecisionManagerInterface $accessDecisionManager;
private ?FirewallMapInterface $firewallMap;
private ?TraceableFirewallListener $firewall;
private bool $hasVarDumper;

public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null, TraceableFirewallListener $firewall = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
final class TraceableFirewallListener extends FirewallListener
{
private $wrappedListeners = [];
private $authenticatorsInfo = [];
private array $wrappedListeners = [];
private array $authenticatorsInfo = [];

public function getWrappedListeners()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\SecurityBundle\Debug;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
use Symfony\Component\VarDumper\Caster\ClassStub;

Expand All @@ -21,10 +22,10 @@
*/
trait TraceableListenerTrait
{
private $response;
private $listener;
private $time;
private $stub;
private ?Response $response = null;
private mixed $listener;
private ?float $time = null;
private object $stub;

/**
* Proxies all method calls to the original listener.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class MainConfiguration implements ConfigurationInterface
/** @internal */
public const STRATEGY_PRIORITY = 'priority';

private $factories;
private $userProviderFactories;
private array $factories;
private array $userProviderFactories;

/**
* @param AuthenticatorFactoryInterface[] $factories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
*/
class SecurityExtension extends Extension implements PrependExtensionInterface
{
private $requestMatchers = [];
private $expressions = [];
private $contextListeners = [];
private array $requestMatchers = [];
private array $expressions = [];
private array $contextListeners = [];
/** @var list<array{0: int, 1: AuthenticatorFactoryInterface}> */
private $factories = [];
private array $factories = [];
/** @var AuthenticatorFactoryInterface[] */
private $sortedFactories = [];
private $userProviderFactories = [];
private array $sortedFactories = [];
private array $userProviderFactories = [];

public function prepend(ContainerBuilder $container)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
class FirewallListener extends Firewall
{
private $map;
private $logoutUrlGenerator;
private FirewallMapInterface $map;
private LogoutUrlGenerator $logoutUrlGenerator;

public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher, LogoutUrlGenerator $logoutUrlGenerator)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class VoteListener implements EventSubscriberInterface
{
private $traceableAccessDecisionManager;
private TraceableAccessDecisionManager $traceableAccessDecisionManager;

public function __construct(TraceableAccessDecisionManager $traceableAccessDecisionManager)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
final class DecoratedRememberMeHandler implements RememberMeHandlerInterface
{
private $handler;
private RememberMeHandlerInterface $handler;

public function __construct(RememberMeHandlerInterface $handler)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Bundle\SecurityBundle\Security;

use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Provides basic functionality for services mapped by the firewall name
* in a container locator.
Expand All @@ -21,9 +24,9 @@
*/
trait FirewallAwareTrait
{
private $locator;
private $requestStack;
private $firewallMap;
private ContainerInterface $locator;
private RequestStack $requestStack;
private FirewallMap $firewallMap;

private function getForFirewall(): object
{
Expand Down
24 changes: 12 additions & 12 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
*/
final class FirewallConfig
{
private $name;
private $userChecker;
private $requestMatcher;
private $securityEnabled;
private $stateless;
private $provider;
private $context;
private $entryPoint;
private $accessDeniedHandler;
private $accessDeniedUrl;
private $authenticators;
private $switchUser;
private string $name;
private string $userChecker;
private ?string $requestMatcher;
private bool $securityEnabled;
private bool $stateless;
private ?string $provider;
private ?string $context;
private ?string $entryPoint;
private ?string $accessDeniedHandler;
private ?string $accessDeniedUrl;
private array $authenticators;
private ?array $switchUser;

public function __construct(string $name, string $userChecker, string $requestMatcher = null, bool $securityEnabled = true, bool $stateless = false, string $provider = null, string $context = null, string $entryPoint = null, string $accessDeniedHandler = null, string $accessDeniedUrl = null, array $authenticators = [], array $switchUser = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
*/
class FirewallContext
{
private $listeners;
private $exceptionListener;
private $logoutListener;
private $config;
private iterable $listeners;
private ?ExceptionListener $exceptionListener;
private ?LogoutListener $logoutListener;
private ?FirewallConfig $config;

public function __construct(iterable $listeners, ExceptionListener $exceptionListener = null, LogoutListener $logoutListener = null, FirewallConfig $config = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
class FirewallMap implements FirewallMapInterface
{
private $container;
private $map;
private ContainerInterface $container;
private iterable $map;

public function __construct(ContainerInterface $container, iterable $map)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class LazyFirewallContext extends FirewallContext
{
private $tokenStorage;
private TokenStorage $tokenStorage;

public function __construct(iterable $listeners, ?ExceptionListener $exceptionListener, ?LogoutListener $logoutListener, ?FirewallConfig $config, TokenStorage $tokenStorage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
class CacheTokenVerifier implements TokenVerifierInterface
{
private $cache;
private $outdatedTokenTtl;
private $cacheKeyPrefix;
private CacheItemPoolInterface $cache;
private int $outdatedTokenTtl;
private string $cacheKeyPrefix;

/**
* @param int $outdatedTokenTtl How long the outdated token should still be considered valid. Defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class InMemoryTokenProvider implements TokenProviderInterface
{
private $tokens = [];
private array $tokens = [];

/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/
final class PersistentToken implements PersistentTokenInterface
{
private $class;
private $userIdentifier;
private $series;
private $tokenValue;
private $lastUsed;
private string $class;
private string $userIdentifier;
private string $series;
private string $tokenValue;
private \DateTime $lastUsed;

public function __construct(string $class, string $userIdentifier, string $series, string $tokenValue, \DateTime $lastUsed)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
*/
abstract class AbstractToken implements TokenInterface, \Serializable
{
private $user;
private $roleNames = [];
private $attributes = [];
private ?UserInterface $user = null;
private array $roleNames = [];
private array $attributes = [];

/**
* @param string[] $roles An array of roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class PreAuthenticatedToken extends AbstractToken
{
private $firewallName;
private string $firewallName;

/**
* @param string[] $roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class RememberMeToken extends AbstractToken
{
private $secret;
private $firewallName;
private string $secret;
private string $firewallName;

/**
* @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
class TokenStorage implements TokenStorageInterface, ResetInterface
{
private $token;
private $initializer;
private ?TokenInterface $token = null;
private ?\Closure $initializer = null;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -56,7 +56,7 @@ public function setToken(TokenInterface $token = null)

public function setInitializer(?callable $initializer): void
{
$this->initializer = $initializer;
$this->initializer = null === $initializer || $initializer instanceof \Closure ? $initializer : \Closure::fromCallable($initializer);
}

public function reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
*/
final class UsageTrackingTokenStorage implements TokenStorageInterface, ServiceSubscriberInterface
{
private $storage;
private $container;
private $enableUsageTracking = false;
private TokenStorageInterface $storage;
private ContainerInterface $container;
private bool $enableUsageTracking = false;

public function __construct(TokenStorageInterface $storage, ContainerInterface $container)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class SwitchUserToken extends UsernamePasswordToken
{
private $originalToken;
private $originatedFromUri;
private TokenInterface $originalToken;
private ?string $originatedFromUri = null;

/**
* @param $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class UsernamePasswordToken extends AbstractToken
{
private $firewallName;
private string $firewallName;

public function __construct(UserInterface $user, string $firewallName, array $roles = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
*/
class AuthorizationChecker implements AuthorizationCheckerInterface
{
private $tokenStorage;
private $accessDecisionManager;
private $exceptionOnNoToken;
private TokenStorageInterface $tokenStorage;
private AccessDecisionManagerInterface $accessDecisionManager;

public function __construct(TokenStorageInterface $tokenStorage, AccessDecisionManagerInterface $accessDecisionManager, bool $exceptionOnNoToken = false)
{
Expand All @@ -37,7 +36,6 @@ public function __construct(TokenStorageInterface $tokenStorage, AccessDecisionM

$this->tokenStorage = $tokenStorage;
$this->accessDecisionManager = $accessDecisionManager;
$this->exceptionOnNoToken = $exceptionOnNoToken;
}

/**
Expand Down
Loading