8000 minor #32238 [DependencyInjection] Added type-hints on compiler passe… · symfony/symfony@faaa83c · GitHub
[go: up one dir, main page]

Skip to content

Commit faaa83c

Browse files
committed
minor #32238 [DependencyInjection] Added type-hints on compiler passes (derrabus)
This PR was merged into the 5.0-dev branch. Discussion ---------- [DependencyInjection] Added type-hints on compiler passes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A First part of type-hints for the DependencyInjection component. I've started with the compiler passes and since there's quite a lot of them, I've decided to split them off. Commits ------- d5bc28a [DependencyInjection] Added type-hints on compiler passes.
2 parents 7739849 + d5bc28a commit faaa83c

28 files changed

+37
-54
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ protected function inExpression(bool $reset = true): bool
6868
* Processes a value found in a definition tree.
6969
*
7070
* @param mixed $value
71-
* @param bool $isRoot
7271
*
7372
* @return mixed The processed value
7473
*/
75-
protected function processValue($value, $isRoot = false)
74+
protected function processValue($value, bool $isRoot = false)
7675
{
7776
if (\is_array($value)) {
7877
foreach ($value as $k => $v) {
@@ -105,14 +104,11 @@ protected function processValue($value, $isRoot = false)
105104
}
106105

107106
/**
108-
* @param Definition $definition
109-
* @param bool $required
110-
*
111107
* @return \ReflectionFunctionAbstract|null
112108
*
113109
* @throws RuntimeException
114110
*/
115-
protected function getConstructor(Definition $definition, $required)
111+
protected function getConstructor(Definition $definition, bool $required)
116112
{
117113
if (\is_string($factory = $definition->getFactory())) {
118114
if (!\function_exists($factory)) {
@@ -161,14 +157,11 @@ protected function getConstructor(Definition $definition, $required)
161157
}
162158

163159
/**
164-
* @param Definition $definition
165-
* @param string $method
166-
*
167160
* @throws RuntimeException
168161
*
169162
* @return \ReflectionFunctionAbstract
170163
*/
171-
protected function getReflectionMethod(Definition $definition, $method)
164+
protected function getReflectionMethod(Definition $definition, string $method)
172165
{
173166
if ('__construct' === $method) {
174167
return $this->getConstructor($definition, true);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function process(ContainerBuilder $container)
7474
}
7575
}
7676

77-
protected function processValue($value, $isRoot = false)
77+
protected function processValue($value, bool $isRoot = false)
7878
{
7979
$lazy = $this->lazy;
8080
$inExpression = $this->inExpression();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function process(ContainerBuilder $container)
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
protected function processValue($value, $isRoot = false)
68+
protected function processValue($value, bool $isRoot = false)
6969
{
7070
try {
7171
return $this->doProcessValue($value, $isRoot);
@@ -80,7 +80,7 @@ protected function processValue($value, $isRoot = false)
8080
}
8181
}
8282

83-
private function doProcessValue($value, $isRoot = false)
83+
private function doProcessValue($value, bool $isRoot = false)
8484
{
8585
if ($value instanceof TypedReference) {
8686
if ($ref = $this->getAutowiredReference($value)) {
@@ -373,7 +373,7 @@ private function set(string $type, string $id)
373373
$this->ambiguousServiceTypes[$type][] = $id;
374374
}
375375

376-
private function createTypeNotFoundMessageCallback(TypedReference $reference, $label)
376+
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label)
377377
{
378378
$container = new ContainerBuilder($this->container->getParameterBag());
379379
$container->setAliases($this->container->getAliases());
@@ -386,7 +386,7 @@ private function createTypeNotFoundMessageCallback(TypedReference $reference, $l
386386
};
387387
}
388388

389-
private function createTypeNotFoundMessage(ContainerBuilder $container, TypedReference $reference, $label, string $currentId)
389+
private function createTypeNotFoundMessage(ContainerBuilder $container, TypedReference $reference, string $label, string $currentId)
390390
{
391391
if (!$r = $container->getReflectionClass($type = $reference->getType(), false)) {
392392
// either $type does not exist or a parent class does not exist
@@ -444,7 +444,7 @@ private function createTypeAlternatives(ContainerBuilder $container, TypedRefere
444444
return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message);
445445
}
446446

447-
private function getAliasesSuggestionForType(ContainerBuilder $container, $type, $extraContext = null)
447+
private function getAliasesSuggestionForType(ContainerBuilder $container, string $type, $extraContext = null)
448448
{
449449
$aliases = [];
450450
foreach (class_parents($type) + class_implements($type) as $parent) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
protected function processValue($value, $isRoot = false)
26+
protected function processValue($value, bool $isRoot = false)
2727
{
2828
$value = parent::processValue($value, $isRoot);
2929

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(bool $throwExceptions = true)
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
protected function processValue($value, $isRoot = false)
35+
protected function processValue($value, bool $isRoot = false)
3636
{
3737
if (!$value instanceof Definition) {
3838
return parent::processValue($value, $isRoot);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function process(ContainerBuilder $container)
4343
}
4444
}
4545

46-
protected function processValue($value, $isRoot = false)
46+
protected function processValue($value, bool $isRoot = false)
4747
{
4848
if (!$value instanceof Reference) {
4949
return parent::processValue($value, $isRoot);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class CheckReferenceValidityPass extends AbstractRecursivePass
2727
{
28-
protected function processValue($value, $isRoot = false)
28+
protected function processValue($value, bool $isRoot = false)
2929
{
3030
if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {
3131
return $value;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,8 @@ public function getServiceReferenceGraph()
5353

5454
/**
5555
* Adds a pass to the PassConfig.
56-
*
57-
* @param CompilerPassInterface $pass A compiler pass
58-
* @param string $type The type of the pass
59-
* @param int $priority Used to sort the passes
6056
*/
61-
public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
57+
public function addPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
6258
{
6359
$this->passConfig->addPass($pass, $type, $priority);
6460
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DefinitionErrorExceptionPass extends AbstractRecursivePass
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
protected function processValue($value, $isRoot = false)
29+
protected function processValue($value, bool $isRoot = false)
3030
{
3131
if (!$value instanceof Definition || !$value->hasErrors()) {
3232
return parent::processValue($value, $isRoot);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line number 10000 Diff line change
@@ -101,7 +101,7 @@ public function process(ContainerBuilder $container)
101101
/**
102102
* {@inheritdoc}
103103
*/
104-
protected function processValue($value, $isRoot = false)
104+
protected function processValue($value, bool $isRoot = false)
105105
{
106106
if ($value instanceof ArgumentInterface) {
107107
// Reference found in ArgumentInterface::getValues() are not inlineable
@@ -155,7 +155,7 @@ protected function processValue($value, $isRoot = false)
155155
*
156156
* @return bool If the definition is inlineable
157157
*/
158-
private function isInlineableDefinition($id, Definition $definition)
158+
private function isInlineableDefinition(string $id, Definition $definition)
159159
{
160160
if ($definition->hasErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic()) {
161161
return false;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,9 @@ public function getPasses()
110110
/**
111111
* Adds a pass.
112112
*
113-
* @param CompilerPassInterface $pass A Compiler pass
114-
* @param string $type The pass type
115-
* @param int $priority Used to sort the passes
116-
*
117113
* @throws InvalidArgumentException when a pass type doesn't exist
118114
*/
119-
public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
115+
public function addPass(CompilerPassInterface $pass, string $type = self::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
120116
{
121117
$property = $type.'Passes';
122118
if (!isset($this->$property)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function process(ContainerBuilder $container)
6060
}
6161
}
6262

63-
private static function validateProvidedTypes($types, $class)
63+
private static function validateProvidedTypes(string $types, string $class)
6464
{
6565
$types = explode('|', $types);
6666

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class RegisterServiceSubscribersPass extends AbstractRecursivePass
2727
{
28-
protected function processValue($value, $isRoot = false)
28+
protected function processValue($value, bool $isRoot = false)
2929
{
3030
if (!$value instanceof Definition || $value->isAbstract() || $value->isSynthetic() || !$value->hasTag('container.service_subscriber')) {
3131
return parent::processValue($value, $isRoot);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function process(ContainerBuilder $container)
7575
/**
7676
* {@inheritdoc}
7777
*/
78-
protected function processValue($value, $isRoot = false)
78+
protected function processValue($value, bool $isRoot = false)
7979
{
8080
if (!$value instanceof Reference) {
8181
return parent::processValue($value, $isRoot);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function process(ContainerBuilder $container)
8080
/**
8181
* {@inheritdoc}
8282
*/
83-
protected function processValue($value, $isRoot = false)
83+
protected function processValue($value, bool $isRoot = false)
8484
{
8585
if ($value instanceof Reference && isset($this->replacements[$referenceId = (string) $value])) {
8686
// Perform the replacement

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function process(ContainerBuilder $container)
9090
/**
9191
* {@inheritdoc}
9292
*/
93-
protected function processValue($value, $isRoot = false)
93+
protected function processValue($value, bool $isRoot = false)
9494
{
9595
if ($value instanceof TypedReference && $value->getType() === (string) $value) {
9696
// Already checked

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ResolveChildDefinitionsPass extends AbstractRecursivePass
2828
{
2929
private $currentPath;
3030

31-
protected function processValue($value, $isRoot = false)
31+
protected function processValue($value, bool $isRoot = false)
3232
{
3333
if (!$value instanceof Definition) {
3434
return parent::processValue($value, $isRoot);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class ResolveEnvPlaceholdersPass extends AbstractRecursivePass
2020
{
21-
protected function processValue($value, $isRoot = false)
21+
protected function proce C2EE ssValue($value, bool $isRoot = false)
2222
{
2323
if (\is_string($value)) {
2424
return $this->container->resolveEnvPlaceholders($value, true);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ResolveFactoryClassPass extends AbstractRecursivePass
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
protected function processValue($value, $isRoot = false)
25+
protected function processValue($value, bool $isRoot = false)
2626
{
2727
if ($value instanceof Definition && \is_array($factory = $value->getFactory()) && null === $factory[0]) {
2828
if (null === $class = $value->getClass()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function process(ContainerBuilder $container)
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
protected function processValue($value, $isRoot = false)
50+
protected function processValue($value, bool $isRoot = false)
5151
{
5252
if ($value instanceof ArgumentInterface) {
5353
return $value;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
4444
}
4545
}
4646

47-
private function processDefinition(ContainerBuilder $container, $id, Definition $definition)
47+
private function processDefinition(ContainerBuilder $container, string $id, Definition $definition)
4848
{
4949
$instanceofConditionals = $definition->getInstanceofConditionals();
5050
$autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : [];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function process(ContainerBuilder $container)
5353
*
5454
* @throws RuntimeException When an invalid reference is found
5555
*/
56-
private function processValue($value, $rootLevel = 0, $level = 0)
56+
private function processValue($value, int $rootLevel = 0, int $level = 0)
5757
{
5858
if ($value instanceof ServiceClosureArgument) {
5959
$value->setValues($this->processValue($value->getValues(), 1, 1));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ResolveNamedArgumentsPass extends AbstractRecursivePass
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
protected function processValue($value, $isRoot = false)
29+
protected function processValue($value, bool $isRoot = false)
3030
{
3131
if (!$value instanceof Definition) {
3232
return parent::processValue($value, $isRoot);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function process(ContainerBuilder $container)
5858
$this->bag = null;
5959
}
6060

61-
protected function processValue($value, $isRoot = false)
61+
protected function processValue($value, bool $isRoot = false)
6262
{
6363
if (\is_string($value)) {
6464
$v = $this->bag->resolveValue($value);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function process(ContainerBuilder $container)
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
protected function processValue($value, $isRoot = false)
45+
protected function processValue($value, bool $isRoot = false)
4646
{
4747
if (!$value instanceof Reference) {
4848
return parent::processValue($value, $isRoot);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ResolveServiceSubscribersPass extends AbstractRecursivePass
2525
{
2626
private $serviceLocator;
2727

28-
protected function processValue($value, $isRoot = false)
28+
protected function processValue($value, bool $isRoot = false)
2929
{
3030
if ($value instanceof Reference && $this->serviceLocator && \in_array((string) $value, [ContainerInterface::class, ServiceProviderInterface::class], true)) {
3131
return new Reference($this->serviceLocator);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ResolveTaggedIteratorArgumentPass extends AbstractRecursivePass
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
protected function processValue($value, $isRoot = false)
28+
protected function processValue($value, bool $isRoot = false)
2929
{
3030
if (!$value instanceof TaggedIteratorArgument) {
3131
return parent::processValue($value, $isRoot);

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

+3Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
2929
{
3030
use PriorityTaggedServiceTrait;
3131

32-
protected function processValue($value, $isRoot = false)
32+
protected function processValue($value, bool $isRoot = false)
3333
{
3434
if ($value instanceof ServiceLocatorArgument) {
3535
if ($value->getTaggedIteratorArgument()) {
@@ -87,11 +87,9 @@ protected function processValue($value, $isRoot = false)
8787
}
8888

8989
/**
90-
* @param ContainerBuilder $container
91-
* @param Reference[] $refMap
92-
* @param string|null $callerId
90+
* @param Reference[] $refMap
9391
*/
94-
public static function register(ContainerBuilder $container, array $refMap, $callerId = null): Reference
92+
public static function register(ContainerBuilder $container, array $refMap, string $callerId = null): Reference
9593
{
9694
foreach ($refMap as $id => $ref) {
9795
if (!$ref instanceof Reference) {

0 commit comments

Comments
 (0)
0