Skip to content

Commit

Permalink
use constructor property promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jun 5, 2024
1 parent 0e786b6 commit 33f83f3
Show file tree
Hide file tree
Showing 80 changed files with 384 additions and 519 deletions.
10 changes: 4 additions & 6 deletions src/Symfony/Component/DependencyInjection/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ class Alias
{
private const DEFAULT_DEPRECATION_TEMPLATE = 'The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future.';

private string $id;
private bool $public;
private array $deprecation = [];

public function __construct(string $id, bool $public = false)
{
$this->id = $id;
$this->public = $public;
public function __construct(
private string $id,
private bool $public = false,
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ final class BoundArgument implements ArgumentInterface

private static int $sequence = 0;

private mixed $value;
private ?int $identifier = null;
private ?bool $used = null;
private int $type;
private ?string $file;

public function __construct(mixed $value, bool $trackUsage = true, int $type = 0, ?string $file = null)
{
$this->value = $value;
public function __construct(
private mixed $value,
bool $trackUsage = true,
private int $type = 0,
private ?string $file = null,
) {
if ($trackUsage) {
$this->identifier = ++self::$sequence;
} else {
$this->used = true;
}
$this->type = $type;
$this->file = $file;
}

public function getValues(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@
*/
class ServiceLocator extends BaseServiceLocator
{
private \Closure $factory;
private array $serviceMap;
private ?array $serviceTypes;

public function __construct(\Closure $factory, array $serviceMap, ?array $serviceTypes = null)
{
$this->factory = $factory;
$this->serviceMap = $serviceMap;
$this->serviceTypes = $serviceTypes;
public function __construct(
private \Closure $factory,
private array $serviceMap,
private ?array $serviceTypes = null,
) {
parent::__construct($serviceMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
*/
class TaggedIteratorArgument extends IteratorArgument
{
private string $tag;
private mixed $indexAttribute;
private ?string $defaultIndexMethod;
private ?string $defaultPriorityMethod;
private bool $needsIndexes;
private array $exclude;
private bool $excludeSelf = true;

/**
* @param string $tag The name of the tag identifying the target services
Expand All @@ -35,21 +31,24 @@ class TaggedIteratorArgument extends IteratorArgument
* @param array $exclude Services to exclude from the iterator
* @param bool $excludeSelf Whether to automatically exclude the referencing service from the iterator
*/
public function __construct(string $tag, ?string $indexAttribute = null, ?string $defaultIndexMethod = null, bool $needsIndexes = false, ?string $defaultPriorityMethod = null, array $exclude = [], bool $excludeSelf = true)
{
public function __construct(
private string $tag,
?string $indexAttribute = null,
?string $defaultIndexMethod = null,
private bool $needsIndexes = false,
?string $defaultPriorityMethod = null,
private array $exclude = [],
private bool $excludeSelf = true,
) {
parent::__construct([]);

if (null === $indexAttribute && $needsIndexes) {
$indexAttribute = preg_match('/[^.]++$/', $tag, $m) ? $m[0] : $tag;
}

$this->tag = $tag;
$this->indexAttribute = $indexAttribute;
$this->defaultIndexMethod = $defaultIndexMethod ?: ($indexAttribute ? 'getDefault'.str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $indexAttribute))).'Name' : null);
$this->needsIndexes = $needsIndexes;
$this->defaultPriorityMethod = $defaultPriorityMethod ?: ($indexAttribute ? 'getDefault'.str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $indexAttribute))).'Priority' : null);
$this->exclude = $exclude;
$this->excludeSelf = $excludeSelf;
}

public function getTag(): string
Expand Down
8 changes: 3 additions & 5 deletions src/Symfony/Component/DependencyInjection/ChildDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
*/
class ChildDefinition extends Definition
{
private string $parent;

/**
* @param string $parent The id of Definition instance to decorate
*/
public function __construct(string $parent)
{
$this->parent = $parent;
public function __construct(
private string $parent,
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass

private ServiceReferenceGraph $graph;
private ?Definition $currentDefinition = null;
private bool $onlyConstructorArguments;
private bool $hasProxyDumper;
private bool $lazy;
private bool $byConstructor;
private bool $byFactory;
Expand All @@ -47,10 +45,10 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass
/**
* @param bool $onlyConstructorArguments Sets this Service Reference pass to ignore method calls
*/
public function __construct(bool $onlyConstructorArguments = false, bool $hasProxyDumper = true)
{
$this->onlyConstructorArguments = $onlyConstructorArguments;
$this->hasProxyDumper = $hasProxyDumper;
public function __construct(
private bool $onlyConstructorArguments = false,
private bool $hasProxyDumper = true,
) {
$this->enableExpressionProcessing();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ class AutowirePass extends AbstractRecursivePass
private array $ambiguousServiceTypes;
private array $autowiringAliases;
private ?string $lastFailure = null;
private bool $throwOnAutowiringException;
private ?string $decoratedClass = null;
private ?string $decoratedId = null;
private object $defaultArgument;
private ?\Closure $restorePreviousValue = null;
private ?self $typesClone = null;

public function __construct(bool $throwOnAutowireException = true)
{
$this->throwOnAutowiringException = $throwOnAutowireException;
public function __construct(
private bool $throwOnAutowiringException = true,
) {
$this->defaultArgument = new class() {
public $value;
public $names;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ class CheckArgumentsValidityPass extends AbstractRecursivePass
{
protected bool $skipScalars = true;

private bool $throwExceptions;

public function __construct(bool $throwExceptions = true)
{
$this->throwExceptions = $throwExceptions;
public function __construct(
private bool $throwExceptions = true,
) {
}

protected function processValue(mixed $value, bool $isRoot = false): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
'string' => true,
];

private bool $autoload;
private array $skippedIds;

private ExpressionLanguage $expressionLanguage;

/**
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
* Defaults to false to save loading code during compilation.
* @param array $skippedIds An array indexed by the service ids to skip
*/
public function __construct(bool $autoload = false, array $skippedIds = [])
{
$this->autoload = $autoload;
$this->skippedIds = $skippedIds;
public function __construct(
private bool $autoload = false,
private array $skippedIds = [],
) {
}

protected function processValue(mixed $value, bool $isRoot = false): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass
{
protected bool $skipScalars = true;

private ?AnalyzeServiceReferencesPass $analyzingPass;
private array $cloningIds = [];
private array $connectedIds = [];
private array $notInlinedIds = [];
private array $inlinedIds = [];
private array $notInlinableIds = [];
private ?ServiceReferenceGraph $graph = null;

public function __construct(?AnalyzeServiceReferencesPass $analyzingPass = null)
{
$this->analyzingPass = $analyzingPass;
public function __construct(
private ?AnalyzeServiceReferencesPass $analyzingPass = null,
) {
}

public function process(ContainerBuilder $container): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
*/
class RegisterReverseContainerPass implements CompilerPassInterface
{
private bool $beforeRemoving;

public function __construct(bool $beforeRemoving)
{
$this->beforeRemoving = $beforeRemoving;
public function __construct(
private bool $beforeRemoving,
) {
}

public function process(ContainerBuilder $container): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,14 @@
*/
class ServiceReferenceGraphEdge
{
private ServiceReferenceGraphNode $sourceNode;
private ServiceReferenceGraphNode $destNode;
private mixed $value;
private bool $lazy;
private bool $weak;
private bool $byConstructor;

public function __construct(ServiceReferenceGraphNode $sourceNode, ServiceReferenceGraphNode $destNode, mixed $value = null, bool $lazy = false, bool $weak = false, bool $byConstructor = false)
{
$this->sourceNode = $sourceNode;
$this->destNode = $destNode;
$this->value = $value;
$this->lazy = $lazy;
$this->weak = $weak;
$this->byConstructor = $byConstructor;
public function __construct(
private ServiceReferenceGraphNode $sourceNode,
private ServiceReferenceGraphNode $destNode,
private mixed $value = null,
private bool $lazy = false,
private bool $weak = false,
private bool $byConstructor = false,
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
*/
class ServiceReferenceGraphNode
{
private string $id;
private array $inEdges = [];
private array $outEdges = [];
private mixed $value;

public function __construct(string $id, mixed $value)
{
$this->id = $id;
$this->value = $value;
public function __construct(
private string $id,
private mixed $value,
) {
}

public function addInEdge(ServiceReferenceGraphEdge $edge): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
*/
class ContainerParametersResource implements ResourceInterface
{
private array $parameters;

/**
* @param array $parameters The container parameters to track
*/
public function __construct(array $parameters)
{
$this->parameters = $parameters;
public function __construct(
private array $parameters,
) {
}

public function __toString(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
*/
class ContainerParametersResourceChecker implements ResourceCheckerInterface
{
private ContainerInterface $container;

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

public function supports(ResourceInterface $metadata): bool
Expand Down
8 changes: 3 additions & 5 deletions src/Symfony/Component/DependencyInjection/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
*/
abstract class Dumper implements DumperInterface
{
protected ContainerBuilder $container;

public function __construct(ContainerBuilder $container)
{
$this->container = $container;
public function __construct(
protected ContainerBuilder $container,
) {
}
}
8 changes: 4 additions & 4 deletions src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
class EnvVarProcessor implements EnvVarProcessorInterface, ResetInterface
{
private ContainerInterface $container;
/** @var \Traversable<EnvVarLoaderInterface> */
private \Traversable $loaders;
/** @var \Traversable<EnvVarLoaderInterface> */
Expand All @@ -31,9 +30,10 @@ class EnvVarProcessor implements EnvVarProcessorInterface, ResetInterface
/**
* @param \Traversable<EnvVarLoaderInterface>|null $loaders
*/
public function __construct(ContainerInterface $container, ?\Traversable $loaders = null)
{
$this->container = $container;
public function __construct(
private ContainerInterface $container,
?\Traversable $loaders = null,
) {
$this->originalLoaders = $this->loaders = $loaders ?? new \ArrayIterator();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
*/
class AutowiringFailedException extends RuntimeException
{
private string $serviceId;
private ?\Closure $messageCallback = null;

public function __construct(string $serviceId, string|\Closure $message = '', int $code = 0, ?\Throwable $previous = null)
{
$this->serviceId = $serviceId;

public function __construct(
private string $serviceId,
string|\Closure $message = '',
int $code = 0,
?\Throwable $previous = null,
) {
if ($message instanceof \Closure && \function_exists('xdebug_is_enabled') && xdebug_is_enabled()) {
$message = $message();
}
Expand Down
Loading

0 comments on commit 33f83f3

Please sign in to comment.