Skip to content

Commit 085bf55

Browse files
committed
ignore PhpParser\Node\Expr\Variable in ContainerInterfaceUnknownServiceRule
1 parent efaff1f commit 085bf55

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Rules/ContainerInterfaceUnknownServiceRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpParser\Node;
1313
use PhpParser\Node\Arg;
1414
use PhpParser\Node\Expr\MethodCall;
15+
use PhpParser\Node\Expr\Variable;
1516

1617
final class ContainerInterfaceUnknownServiceRule implements Rule
1718
{
@@ -41,6 +42,7 @@ public function processNode(Node $node, Scope $scope): array
4142
if (($isInstanceOfController || $isContainerInterface)
4243
&& isset($node->args[0])
4344
&& $node->args[0] instanceof Arg
45+
&& !$node->args[0]->value instanceof Variable
4446
) {
4547
$service = $this->serviceMap->getServiceFromNode($node->args[0]->value);
4648
if ($service === \null) {

tests/Rules/data/ExampleController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ public function getUnknownService()
2121
$service->noMethod();
2222
}
2323

24+
public function getVariableService(string $serviceKey)
25+
{
26+
$service = $this->get($serviceKey);
27+
$service->noMethod();
28+
}
29+
2430
}

0 commit comments

Comments
 (0)