Skip to content

Commit d948312

Browse files
minor #41928 [DependencyInjection] Add types to private properties (derrabus)
This PR was merged into the 6.0 branch. Discussion ---------- [DependencyInjection] Add types to private properties | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Same procedure as #41924, but on a more complex component. Commits ------- 069da20 [DependencyInjection] Add types to private properties
2 parents f111c94 + 069da20 commit d948312

File tree

76 files changed

+297
-400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+297
-400
lines changed

src/Symfony/Component/DependencyInjection/Alias.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class Alias
1717
{
1818
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.';
1919

20-
private $id;
21-
private $public;
22-
private $deprecation = [];
20+
private string $id;
21+
private bool $public;
22+
private array $deprecation = [];
2323

2424
public function __construct(string $id, bool $public = false)
2525
{

src/Symfony/Component/DependencyInjection/Argument/AbstractArgument.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
final class AbstractArgument
1818
{
19-
private $text;
20-
private $context;
19+
private string $text;
20+
private string $context = '';
2121

2222
public function __construct(string $text = '')
2323
{

src/Symfony/Component/DependencyInjection/Argument/BoundArgument.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ final class BoundArgument implements ArgumentInterface
2020
public const DEFAULTS_BINDING = 1;
2121
public const INSTANCEOF_BINDING = 2;
2222

23-
private static $sequence = 0;
23+
private static int $sequence = 0;
2424

25-
private $value;
26-
private $identifier;
27-
private $used;
28-
private $type;
29-
private $file;
25+
private mixed $value;
26+
private ?int $identifier = null;
27+
private ?bool $used = null;
28+
private int $type;
29+
private ?string $file;
3030

3131
public function __construct(mixed $value, bool $trackUsage = true, int $type = 0, string $file = null)
3232
{

src/Symfony/Component/DependencyInjection/Argument/ReferenceSetArgumentTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
trait ReferenceSetArgumentTrait
2222
{
23-
private $values;
23+
private array $values;
2424

2525
/**
2626
* @param Reference[] $values

src/Symfony/Component/DependencyInjection/Argument/RewindableGenerator.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*/
1717
class RewindableGenerator implements \IteratorAggregate, \Countable
1818
{
19-
private $generator;
20-
private $count;
19+
private \Closure $generator;
20+
private \Closure|int $count;
2121

2222
public function __construct(callable $generator, int|callable $count)
2323
{
24-
$this->generator = $generator;
25-
$this->count = $count;
24+
$this->generator = $generator instanceof \Closure ? $generator : \Closure::fromCallable($generator);
25+
$this->count = is_callable($count) && !$count instanceof \Closure ? \Closure::fromCallable($count) : $count;
2626
}
2727

2828
public function getIterator(): \Traversable

src/Symfony/Component/DependencyInjection/Argument/ServiceClosureArgument.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class ServiceClosureArgument implements ArgumentInterface
2323
{
24-
private $values;
24+
private array $values;
2525

2626
public function __construct(Reference $reference)
2727
{

src/Symfony/Component/DependencyInjection/Argument/ServiceLocator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
class ServiceLocator extends BaseServiceLocator
2222
{
23-
private $factory;
24-
private $serviceMap;
25-
private $serviceTypes;
23+
private \Closure $factory;
24+
private array $serviceMap;
25+
private ?array $serviceTypes;
2626

2727
public function __construct(\Closure $factory, array $serviceMap, array $serviceTypes = null)
2828
{

src/Symfony/Component/DependencyInjection/Argument/ServiceLocatorArgument.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ServiceLocatorArgument implements ArgumentInterface
2222
{
2323
use ReferenceSetArgumentTrait;
2424

25-
private $taggedIteratorArgument;
25+
private ?TaggedIteratorArgument $taggedIteratorArgument = null;
2626

2727
/**
2828
* @param Reference[]|TaggedIteratorArgument $values

src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
class TaggedIteratorArgument extends IteratorArgument
2020
{
21-
private $tag;
22-
private $indexAttribute;
23-
private $defaultIndexMethod;
24-
private $defaultPriorityMethod;
25-
private $needsIndexes = false;
21+
private string $tag;
22+
private mixed $indexAttribute;
23+
private ?string $defaultIndexMethod;
24+
private ?string $defaultPriorityMethod;
25+
private bool $needsIndexes;
2626

2727
/**
2828
* @param string $tag The name of the tag identifying the target services

src/Symfony/Component/DependencyInjection/ChildDefinition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class ChildDefinition extends Definition
2323
{
24-
private $parent;
24+
private string $parent;
2525

2626
/**
2727
* @param string $parent The id of Definition instance to decorate

src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
3131
protected $container;
3232
protected $currentId;
3333

34-
private $processExpressions = false;
35-
private $expressionLanguage;
36-
private $inExpression = false;
34+
private bool $processExpressions = false;
35+
private ExpressionLanguage $expressionLanguage;
36+
private bool $inExpression = false;
3737

3838
/**
3939
* {@inheritdoc}
@@ -194,7 +194,7 @@ protected function getReflectionMethod(Definition $definition, string $method)
194194

195195
private function getExpressionLanguage(): ExpressionLanguage
196196
{
197-
if (null === $this->expressionLanguage) {
197+
if (!isset($this->expressionLanguage)) {
198198
if (!class_exists(ExpressionLanguage::class)) {
199199
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
200200
}

src/Symfony/Component/DependencyInjection/Compiler/AliasDeprecatedPublicServicesPass.php

+5-16
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@
1717

1818
final class AliasDeprecatedPublicServicesPass extends AbstractRecursivePass
1919
{
20-
private $tagName;
21-
22-
private $aliases = [];
23-
24-
public function __construct(string $tagName = 'container.private')
25-
{
26-
if (0 < \func_num_args()) {
27-
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
28-
}
29-
30-
$this->tagName = $tagName;
31-
}
20+
private array $aliases = [];
3221

3322
/**
3423
* {@inheritdoc}
@@ -47,13 +36,13 @@ protected function processValue(mixed $value, bool $isRoot = false)
4736
*/
4837
public function process(ContainerBuilder $container)
4938
{
50-
foreach ($container->findTaggedServiceIds($this->tagName) as $id => $tags) {
39+
foreach ($container->findTaggedServiceIds('container.private') as $id => $tags) {
5140
if (null === $package = $tags[0]['package'] ?? null) {
52-
throw new InvalidArgumentException(sprintf('The "package" attribute is mandatory for the "%s" tag on the "%s" service.', $this->tagName, $id));
41+
throw new InvalidArgumentException(sprintf('The "package" attribute is mandatory for the "container.private" tag on the "%s" service.', $id));
5342
}
5443

5544
if (null === $version = $tags[0]['version'] ?? null) {
56-
throw new InvalidArgumentException(sprintf('The "version" attribute is mandatory for the "%s" tag on the "%s" service.', $this->tagName, $id));
45+
throw new InvalidArgumentException(sprintf('The "version" attribute is mandatory for the "container.private" tag on the "%s" service.', $id));
5746
}
5847

5948
$definition = $container->getDefinition($id);
@@ -62,7 +51,7 @@ public function process(ContainerBuilder $container)
6251
}
6352

6453
$container
65-
->setAlias($id, $aliasId = '.'.$this->tagName.'.'.$id)
54+
->setAlias($id, $aliasId = '.container.private.'.$id)
6655
->setPublic(true)
6756
->setDeprecated($package, $version, 'Accessing the "%alias_id%" service directly from the container is deprecated, use dependency injection instead.');
6857

src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
*/
3131
class AnalyzeServiceReferencesPass extends AbstractRecursivePass
3232
{
33-
private $graph;
34-
private $currentDefinition;
35-
private $onlyConstructorArguments;
36-
private $hasProxyDumper;
37-
private $lazy;
38-
private $byConstructor;
39-
private $byFactory;
40-
private $definitions;
41-
private $aliases;
33+
private ServiceReferenceGraph $graph;
34+
private ?Definition $currentDefinition = null;
35+
private bool $onlyConstructorArguments;
36+
private bool $hasProxyDumper;
37+
private bool $lazy;
38+
private bool $byConstructor;
39+
private bool $byFactory;
40+
private array $definitions;
41+
private array $aliases;
4242

4343
/**
4444
* @param bool $onlyConstructorArguments Sets this Service Reference pass to ignore method calls

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
*/
3333
class AutowirePass extends AbstractRecursivePass
3434
{
35-
private $types;
36-
private $ambiguousServiceTypes;
37-
private $autowiringAliases;
38-
private $lastFailure;
39-
private $throwOnAutowiringException;
40-
private $decoratedClass;
41-
private $decoratedId;
42-
private $methodCalls;
43-
private $getPreviousValue;
44-
private $decoratedMethodIndex;
45-
private $decoratedMethodArgumentIndex;
46-
private $typesClone;
35+
private array $types;
36+
private array $ambiguousServiceTypes;
37+
private array $autowiringAliases;
38+
private ?string $lastFailure = null;
39+
private bool $throwOnAutowiringException;
40+
private ?string $decoratedClass = null;
41+
private ?string $decoratedId = null;
42+
private ?array $methodCalls = null;
43+
private ?\Closure $getPreviousValue = null;
44+
private ?int $decoratedMethodIndex = null;
45+
private ?int $decoratedMethodArgumentIndex = null;
46+
private ?self $typesClone = null;
4747

4848
public function __construct(bool $throwOnAutowireException = true)
4949
{
@@ -460,7 +460,7 @@ private function createTypeAlternatives(ContainerBuilder $container, TypedRefere
460460
if ($message = $this->getAliasesSuggestionForType($container, $type = $reference->getType())) {
461461
return ' '.$message;
462462
}
463-
if (null === $this->ambiguousServiceTypes) {
463+
if (!isset($this->ambiguousServiceTypes)) {
464464
$this->populateAvailableTypes($container);
465465
}
466466

src/Symfony/Component/DependencyInjection/Compiler/CheckArgumentsValidityPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class CheckArgumentsValidityPass extends AbstractRecursivePass
2424
{
25-
private $throwExceptions;
25+
private bool $throwExceptions;
2626

2727
public function __construct(bool $throwExceptions = true)
2828
{

src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
*/
2727
class CheckCircularReferencesPass implements CompilerPassInterface
2828
{
29-
private $currentPath;
30-
private $checkedNodes;
29+
private array $currentPath;
30+
private array $checkedNodes;
3131

3232
/**
3333
* Checks the ContainerBuilder object for circular references.

src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
2525
{
26-
private $serviceLocatorContextIds = [];
26+
private array $serviceLocatorContextIds = [];
2727

2828
/**
2929
* {@inheritdoc}

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
5959
'string' => true,
6060
];
6161

62-
private $autoload;
63-
private $skippedIds;
62+
private bool $autoload;
63+
private array $skippedIds;
6464

65-
private $expressionLanguage;
65+
private ExpressionLanguage $expressionLanguage;
6666

6767
/**
6868
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
@@ -309,10 +309,6 @@ private function checkType(Definition $checkedDefinition, mixed $value, \Reflect
309309

310310
private function getExpressionLanguage(): ExpressionLanguage
311311
{
312-
if (null === $this->expressionLanguage) {
313-
$this->expressionLanguage = new ExpressionLanguage(null, $this->container->getExpressionLanguageProviders());
314-
}
315-
316-
return $this->expressionLanguage;
312+
return $this->expressionLanguage ??= new ExpressionLanguage(null, $this->container->getExpressionLanguageProviders());
317313
}
318314
}

src/Symfony/Component/DependencyInjection/Compiler/Compiler.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class Compiler
2323
{
24-
private $passConfig;
25-
private $log = [];
26-
private $serviceReferenceGraph;
24+
private PassConfig $passConfig;
25+
private array $log = [];
26+
private ServiceReferenceGraph $serviceReferenceGraph;
2727

2828
public function __construct()
2929
{

src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@
2727
*/
2828
class DecoratorServicePass extends AbstractRecursivePass
2929
{
30-
private $innerId = '.inner';
31-
32-
public function __construct(?string $innerId = '.inner')
33-
{
34-
if (0 < \func_num_args()) {
35-
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
36-
}
37-
38-
$this->innerId = $innerId;
39-
}
40-
4130
public function process(ContainerBuilder $container)
4231
{
4332
$definitions = new \SplPriorityQueue();
@@ -123,7 +112,7 @@ public function process(ContainerBuilder $container)
123112

124113
protected function processValue(mixed $value, bool $isRoot = false)
125114
{
126-
if ($value instanceof Reference && $this->innerId === (string) $value) {
115+
if ($value instanceof Reference && '.inner' === (string) $value) {
127116
return new Reference($this->currentId, $value->getInvalidBehavior());
128117
}
129118

src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
*/
2525
class InlineServiceDefinitionsPass extends AbstractRecursivePass
2626
{
27-
private $analyzingPass;
28-
private $cloningIds = [];
29-
private $connectedIds = [];
30-
private $notInlinedIds = [];
31-
private $inlinedIds = [];
32-
private $notInlinableIds = [];
33-
private $graph;
27+
private ?AnalyzeServiceReferencesPass $analyzingPass;
28+
private array $cloningIds = [];
29+
private array $connectedIds = [];
30+
private array $notInlinedIds = [];
31+
private array $inlinedIds = [];
32+
private array $notInlinableIds = [];
33+
private ?ServiceReferenceGraph $graph = null;
3434

3535
public function __construct(AnalyzeServiceReferencesPass $analyzingPass = null)
3636
{

0 commit comments

Comments
 (0)