diff --git a/src/Type/Symfony/ServiceDynamicReturnTypeExtension.php b/src/Type/Symfony/ServiceDynamicReturnTypeExtension.php index 6b2f6f84..9d028c35 100644 --- a/src/Type/Symfony/ServiceDynamicReturnTypeExtension.php +++ b/src/Type/Symfony/ServiceDynamicReturnTypeExtension.php @@ -68,7 +68,7 @@ private function getGetTypeFromMethodCall( $serviceId = $this->serviceMap::getServiceIdFromNode($methodCall->args[0]->value, $scope); if ($serviceId !== null) { $service = $this->serviceMap->getService($serviceId); - if ($service !== null && !$service->isSynthetic()) { + if ($service !== null && (!$service->isSynthetic() || $service->getClass() !== null)) { return new ObjectType($service->getClass() ?? $serviceId); } } diff --git a/tests/Type/Symfony/container.xml b/tests/Type/Symfony/container.xml index 25966148..5bedede2 100644 --- a/tests/Type/Symfony/container.xml +++ b/tests/Type/Symfony/container.xml @@ -38,5 +38,6 @@ + diff --git a/tests/Type/Symfony/data/ExampleAbstractController.php b/tests/Type/Symfony/data/ExampleAbstractController.php index ffb4e33f..4dbaffa7 100644 --- a/tests/Type/Symfony/data/ExampleAbstractController.php +++ b/tests/Type/Symfony/data/ExampleAbstractController.php @@ -13,11 +13,13 @@ final class ExampleAbstractController extends AbstractController public function services(): void { assertType('Foo', $this->get('foo')); + assertType('Synthetic', $this->get('synthetic')); assertType('object', $this->get('bar')); assertType('object', $this->get(doFoo())); assertType('object', $this->get()); assertType('true', $this->has('foo')); + assertType('true', $this->has('synthetic')); assertType('false', $this->has('bar')); assertType('bool', $this->has(doFoo())); assertType('bool', $this->has()); diff --git a/tests/Type/Symfony/data/ExampleAbstractControllerWithoutContainer.php b/tests/Type/Symfony/data/ExampleAbstractControllerWithoutContainer.php index 28773829..7ca06775 100644 --- a/tests/Type/Symfony/data/ExampleAbstractControllerWithoutContainer.php +++ b/tests/Type/Symfony/data/ExampleAbstractControllerWithoutContainer.php @@ -12,11 +12,13 @@ final class ExampleAbstractControllerWithoutContainer extends AbstractController public function services(): void { assertType('object', $this->get('foo')); + assertType('object', $this->get('synthetic')); assertType('object', $this->get('bar')); assertType('object', $this->get(doFoo())); assertType('object', $this->get()); assertType('bool', $this->has('foo')); + assertType('bool', $this->has('synthetic')); assertType('bool', $this->has('bar')); assertType('bool', $this->has(doFoo())); assertType('bool', $this->has()); diff --git a/tests/Type/Symfony/data/ExampleController.php b/tests/Type/Symfony/data/ExampleController.php index 576f8369..1fe8c983 100644 --- a/tests/Type/Symfony/data/ExampleController.php +++ b/tests/Type/Symfony/data/ExampleController.php @@ -13,11 +13,13 @@ final class ExampleController extends Controller public function services(): void { assertType('Foo', $this->get('foo')); + assertType('Synthetic', $this->get('synthetic')); assertType('object', $this->get('bar')); assertType('object', $this->get(doFoo())); assertType('object', $this->get()); assertType('true', $this->has('foo')); + assertType('true', $this->has('synthetic')); assertType('false', $this->has('bar')); assertType('bool', $this->has(doFoo())); assertType('bool', $this->has()); diff --git a/tests/Type/Symfony/data/ExampleControllerWithoutContainer.php b/tests/Type/Symfony/data/ExampleControllerWithoutContainer.php index 2adfd7d5..2e9b7ba2 100644 --- a/tests/Type/Symfony/data/ExampleControllerWithoutContainer.php +++ b/tests/Type/Symfony/data/ExampleControllerWithoutContainer.php @@ -12,11 +12,13 @@ final class ExampleControllerWithoutContainer extends Controller public function services(): void { assertType('object', $this->get('foo')); + assertType('object', $this->get('synthetic')); assertType('object', $this->get('bar')); assertType('object', $this->get(doFoo())); assertType('object', $this->get()); assertType('bool', $this->has('foo')); + assertType('bool', $this->has('synthetic')); assertType('bool', $this->has('bar')); assertType('bool', $this->has(doFoo())); assertType('bool', $this->has());