Skip to content

Commit 5d0da0e

Browse files
committed
Fixed empty resolved service name
1 parent a53fed9 commit 5d0da0e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Rules/ContainerInterfaceUnknownServiceRule.php

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

1716
final class ContainerInterfaceUnknownServiceRule implements Rule
1817
{
@@ -42,11 +41,13 @@ public function processNode(Node $node, Scope $scope): array
4241
if (($isInstanceOfController || $isContainerInterface)
4342
&& isset($node->args[0])
4443
&& $node->args[0] instanceof Arg
45-
&& !$node->args[0]->value instanceof Variable
4644
) {
4745
$service = $this->serviceMap->getServiceFromNode($node->args[0]->value);
4846
if ($service === \null) {
49-
return [\sprintf('Service "%s" is not registered in the container.', ServiceMap::getServiceIdFromNode($node->args[0]->value))];
47+
$serviceId = ServiceMap::getServiceIdFromNode($node->args[0]->value);
48+
if ($serviceId !== null) {
49+
return [\sprintf('Service "%s" is not registered in the container.', $serviceId)];
50+
}
5051
}
5152
}
5253
}

tests/Rules/data/ExampleController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public function getVariableService(string $serviceKey)
2727
$service->noMethod();
2828
}
2929

30+
public function getConcatenatedService(string $serviceKey)
31+
{
32+
$service = $this->get('service.' . self::class);
33+
$service->noMethod();
34+
}
35+
3036
}

0 commit comments

Comments
 (0)