Skip to content

Commit

Permalink
use constructor property promotion in SecurityBundle and TwigBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed May 24, 2024
1 parent 1f90bc3 commit a39d10d
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
*/
class ExpressionCacheWarmer implements CacheWarmerInterface
{
private iterable $expressions;
private ExpressionLanguage $expressionLanguage;

/**
* @param iterable<mixed, Expression|string> $expressions
*/
public function __construct(iterable $expressions, ExpressionLanguage $expressionLanguage)
{
$this->expressions = $expressions;
$this->expressionLanguage = $expressionLanguage;
public function __construct(
private iterable $expressions,
private ExpressionLanguage $expressionLanguage,
) {
}

public function isOptional(): bool
Expand Down
18 changes: 6 additions & 12 deletions src/Symfony/Bundle/SecurityBundle/Command/DebugFirewallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,16 @@
#[AsCommand(name: 'debug:firewall', description: 'Display information about your security firewall(s)')]
final class DebugFirewallCommand extends Command
{
private array $firewallNames;
private ContainerInterface $contexts;
private ContainerInterface $eventDispatchers;
private array $authenticators;

/**
* @param string[] $firewallNames
* @param AuthenticatorInterface[][] $authenticators
*/
public function __construct(array $firewallNames, ContainerInterface $contexts, ContainerInterface $eventDispatchers, array $authenticators)
{
$this->firewallNames = $firewallNames;
$this->contexts = $contexts;
$this->eventDispatchers = $eventDispatchers;
$this->authenticators = $authenticators;

public function __construct(
private array $firewallNames,
private ContainerInterface $contexts,
private ContainerInterface $eventDispatchers,
private array $authenticators
) {
parent::__construct();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,16 @@
*/
class SecurityDataCollector extends DataCollector implements LateDataCollectorInterface
{
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)
{
$this->tokenStorage = $tokenStorage;
$this->roleHierarchy = $roleHierarchy;
$this->logoutUrlGenerator = $logoutUrlGenerator;
$this->accessDecisionManager = $accessDecisionManager;
$this->firewallMap = $firewallMap;
$this->firewall = $firewall;
public function __construct(
private ?TokenStorageInterface $tokenStorage = null,
private ?RoleHierarchyInterface $roleHierarchy = null,
private ?LogoutUrlGenerator $logoutUrlGenerator = null,
private ?AccessDecisionManagerInterface $accessDecisionManager = null,
private ?FirewallMapInterface $firewallMap = null,
private ?TraceableFirewallListener $firewall = null,
) {
$this->hasVarDumper = class_exists(ClassStub::class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ class MainConfiguration implements ConfigurationInterface
/** @internal */
public const STRATEGY_PRIORITY = 'priority';

private array $factories;
private array $userProviderFactories;

/**
* @param array<AuthenticatorFactoryInterface> $factories
*/
public function __construct(array $factories, array $userProviderFactories)
{
$this->factories = $factories;
$this->userProviderFactories = $userProviderFactories;
public function __construct(
private array $factories,
private array $userProviderFactories
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
*/
class FirewallListener extends Firewall
{
private FirewallMapInterface $map;
private LogoutUrlGenerator $logoutUrlGenerator;

public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher, LogoutUrlGenerator $logoutUrlGenerator)
{
$this->map = $map;
$this->logoutUrlGenerator = $logoutUrlGenerator;

public function __construct(
private FirewallMapInterface $map,
EventDispatcherInterface $dispatcher,
private LogoutUrlGenerator $logoutUrlGenerator
) {
parent::__construct($map, $dispatcher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
*/
class VoteListener implements EventSubscriberInterface
{
private TraceableAccessDecisionManager $traceableAccessDecisionManager;

public function __construct(TraceableAccessDecisionManager $traceableAccessDecisionManager)
{
$this->traceableAccessDecisionManager = $traceableAccessDecisionManager;
public function __construct(
private TraceableAccessDecisionManager $traceableAccessDecisionManager,
) {
}

public function onVoterVote(VoteEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
*/
final class DecoratedRememberMeHandler implements RememberMeHandlerInterface
{
private RememberMeHandlerInterface $handler;

public function __construct(RememberMeHandlerInterface $handler)
{
$this->handler = $handler;
public function __construct(
private RememberMeHandlerInterface $handler,
) {
}

public function createRememberMeCookie(UserInterface $user): void
Expand Down
17 changes: 6 additions & 11 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
*/
class FirewallContext
{
private iterable $listeners;
private ?ExceptionListener $exceptionListener;
private ?LogoutListener $logoutListener;
private ?FirewallConfig $config;

/**
* @param iterable<mixed, callable> $listeners
*/
public function __construct(iterable $listeners, ?ExceptionListener $exceptionListener = null, ?LogoutListener $logoutListener = null, ?FirewallConfig $config = null)
{
$this->listeners = $listeners;
$this->exceptionListener = $exceptionListener;
$this->logoutListener = $logoutListener;
$this->config = $config;
public function __construct(
private iterable $listeners,
private ?ExceptionListener $exceptionListener = null,
private ?LogoutListener $logoutListener = null,
private ?FirewallConfig $config = null,
) {
}

public function getConfig(): ?FirewallConfig
Expand Down
11 changes: 4 additions & 7 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
*/
class FirewallMap implements FirewallMapInterface
{
private ContainerInterface $container;
private iterable $map;

public function __construct(ContainerInterface $container, iterable $map)
{
$this->container = $container;
$this->map = $map;
public function __construct(
private ContainerInterface $container,
private iterable $map,
) {
}

public function getListeners(Request $request): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
*/
class LazyFirewallContext extends FirewallContext
{
private TokenStorage $tokenStorage;

public function __construct(iterable $listeners, ?ExceptionListener $exceptionListener, ?LogoutListener $logoutListener, ?FirewallConfig $config, TokenStorage $tokenStorage)
{
public function __construct(
iterable $listeners,
?ExceptionListener $exceptionListener,
?LogoutListener $logoutListener,
?FirewallConfig $config,
private TokenStorage $tokenStorage,
) {
parent::__construct($listeners, $exceptionListener, $logoutListener, $config);

$this->tokenStorage = $tokenStorage;
}

public function getListeners(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
*/
class TemplateCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
{
private ContainerInterface $container;
private Environment $twig;
private iterable $iterator;

public function __construct(ContainerInterface $container, iterable $iterator)
{
// As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
$this->container = $container;
$this->iterator = $iterator;
/**
* As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
*/
public function __construct(
private ContainerInterface $container,
private iterable $iterator
) {
}

public function warmUp(string $cacheDir, ?string $buildDir = null): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,14 @@
*/
class EnvironmentConfigurator
{
private string $dateFormat;
private string $intervalFormat;
private ?string $timezone;
private int $decimals;
private string $decimalPoint;
private string $thousandsSeparator;

public function __construct(string $dateFormat, string $intervalFormat, ?string $timezone, int $decimals, string $decimalPoint, string $thousandsSeparator)
{
$this->dateFormat = $dateFormat;
$this->intervalFormat = $intervalFormat;
$this->timezone = $timezone;
$this->decimals = $decimals;
$this->decimalPoint = $decimalPoint;
$this->thousandsSeparator = $thousandsSeparator;
public function __construct(
private string $dateFormat,
private string $intervalFormat,
private ?string $timezone,
private int $decimals,
private string $decimalPoint,
private string $thousandsSeparator,
) {
}

public function configure(Environment $environment): void
Expand Down
16 changes: 6 additions & 10 deletions src/Symfony/Bundle/TwigBundle/TemplateIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@
*/
class TemplateIterator implements \IteratorAggregate
{
private KernelInterface $kernel;
private \Traversable $templates;
private array $paths;
private ?string $defaultPath;
private array $namePatterns;

/**
* @param array $paths Additional Twig paths to warm
* @param string|null $defaultPath The directory where global templates can be stored
* @param string[] $namePatterns Pattern of file names
*/
public function __construct(KernelInterface $kernel, array $paths = [], ?string $defaultPath = null, array $namePatterns = [])
{
$this->kernel = $kernel;
$this->paths = $paths;
$this->defaultPath = $defaultPath;
$this->namePatterns = $namePatterns;
public function __construct(
private KernelInterface $kernel,
private array $paths = [],
private ?string $defaultPath = null,
private array $namePatterns = [],
) {
}

public function getIterator(): \Traversable
Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Contracts/Service/ServiceLocatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ class_exists(NotFoundExceptionInterface::class);
*/
trait ServiceLocatorTrait
{
private array $factories;
private array $loading = [];
private array $providedTypes;

/**
* @param array<string, callable> $factories
*/
public function __construct(array $factories)
{
$this->factories = $factories;
public function __construct(
private array $factories,
) {
}

public function has(string $id): bool
Expand Down

0 comments on commit a39d10d

Please sign in to comment.