Skip to content

Commit 112d316

Browse files
committed
fix skip use on Symfony\Component\DependencyInjection\Loader\Configurator\ServiceConfigurator
1 parent 9a36e8a commit 112d316

File tree

6 files changed

+51
-23
lines changed

6 files changed

+51
-23
lines changed

rules-tests/Php81/Rector/Array_/ArrayToFirstClassCallableRector/Fixture/skip_as_service_factory_arg.php.inc

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function match(
7373
}
7474

7575
if ($array->getAttribute(AttributeKey::IS_ARG_VALUE) === true && (bool) $array->getAttribute(
76-
AttributeKey::IS_ARG_VALUE_CALLABLE
76+
AttributeKey::IS_ARG_VALUE_FACTORY_SERVICECONFIGURATOR
7777
) === false) {
7878
return null;
7979
}

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,5 @@ final class AttributeKey
167167

168168
public const string IS_IN_TRY_BLOCK = 'is_in_try_block';
169169

170-
public const string IS_ARG_VALUE_CALLABLE = 'is_arg_value_callable';
170+
public const string IS_ARG_VALUE_FACTORY_SERVICECONFIGURATOR = 'is_arg_value_factory_serviceconfigurator';
171171
}

src/PhpParser/NodeVisitor/ContextNodeVisitor.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,15 @@ public function enterNode(Node $node): ?Node
103103

104104
if ($node instanceof CallLike && ! $node->isFirstClassCallable()) {
105105
$functionReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
106-
if (! $functionReflection instanceof FunctionReflection && ! $functionReflection instanceof MethodReflection) {
106+
if (! $functionReflection instanceof MethodReflection) {
107+
return null;
108+
}
109+
110+
if ($functionReflection->getDeclaringClass()->getName() !== 'Symfony\Component\DependencyInjection\Loader\Configurator\ServiceConfigurator') {
111+
return null;
112+
}
113+
114+
if ($functionReflection->getName() !== 'factory') {
107115
return null;
108116
}
109117

@@ -120,26 +128,21 @@ public function enterNode(Node $node): ?Node
120128

121129
$args = $node->getArgs();
122130
foreach ($parametersAcceptor->getParameters() as $key => $parameterReflection) {
123-
// also process maybe callable
124-
if ($parameterReflection->getType()->isCallable()->no()) {
125-
continue;
126-
}
127-
128-
if ($parameterReflection->getType() instanceof ArrayType) {
131+
if ($parameterReflection->getName() !== 'factory') {
129132
continue;
130133
}
131134

132135
// based on name
133136
foreach ($args as $arg) {
134-
if ($arg->name instanceof Identifier && $parameterReflection->getName() === $arg->name->toString()) {
135-
$arg->value->setAttribute(AttributeKey::IS_ARG_VALUE_CALLABLE, true);
137+
if ($arg->name instanceof Identifier && 'factory' === $arg->name->toString()) {
138+
$arg->value->setAttribute(AttributeKey::IS_ARG_VALUE_FACTORY_SERVICECONFIGURATOR, true);
136139
continue 2;
137140
}
138141
}
139142

140143
// based on key
141144
if (isset($args[$key])) {
142-
$args[$key]->value->setAttribute(AttributeKey::IS_ARG_VALUE_CALLABLE, true);
145+
$args[$key]->value->setAttribute(AttributeKey::IS_ARG_VALUE_FACTORY_SERVICECONFIGURATOR, true);
143146
}
144147
}
145148
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
6+
use Symfony\Component\ExpressionLanguage\Expression;
7+
8+
if (class_exists('Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ContainerConfigurator')) {
9+
return;
10+
}
11+
12+
class ContainerConfigurator
13+
{
14+
public function services(): ServiceConfigurator
15+
{
16+
return new ServiceConfigurator();
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
6+
use Symfony\Component\ExpressionLanguage\Expression;
7+
8+
if (class_exists('Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ServiceConfigurator')) {
9+
return;
10+
}
11+
12+
class ServiceConfigurator
13+
{
14+
function factory(string|array|ReferenceConfigurator|Expression $factory): static
15+
{
16+
return $this;
17+
}
18+
}

0 commit comments

Comments
 (0)