Skip to content

Commit

Permalink
Fix synthetic service return type when class is available
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed May 5, 2021
1 parent 34f16fa commit 7f47026
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Type/Symfony/ServiceDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Type/Symfony/container.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@

<services>
<service id="foo" class="Foo"></service>
<service id="synthetic" class="Synthetic" synthetic="true" />
</services>
</container>
2 changes: 2 additions & 0 deletions tests/Type/Symfony/data/ExampleAbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/Type/Symfony/data/ExampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/Type/Symfony/data/ExampleControllerWithoutContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 7f47026

Please sign in to comment.