|
7 | 7 | use PHPStan\Analyser\Scope; |
8 | 8 | use PHPStan\Reflection\MethodReflection; |
9 | 9 | use PHPStan\Reflection\ParametersAcceptorSelector; |
| 10 | +use PHPStan\Type\BooleanType; |
10 | 11 | use PHPStan\Type\Constant\ConstantBooleanType; |
11 | 12 | use PHPStan\Type\DynamicMethodReturnTypeExtension; |
12 | 13 | use PHPStan\Type\NullType; |
|
18 | 19 |
|
19 | 20 | class ContainerDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension |
20 | 21 | { |
21 | | - /** |
22 | | - * @var ServiceMap |
23 | | - */ |
24 | | - private ServiceMap $serviceMap; |
25 | 22 |
|
26 | | - public function __construct(ServiceMap $serviceMap) |
27 | | - { |
28 | | - $this->serviceMap = $serviceMap; |
| 23 | + public function __construct( |
| 24 | + private ServiceMap $serviceMap, |
| 25 | + private bool $containerHasAlwaysTrue, |
| 26 | + ) { |
29 | 27 | } |
30 | 28 |
|
31 | 29 | public function getClass(): string |
@@ -62,7 +60,11 @@ public function getTypeFromMethodCall( |
62 | 60 | foreach ($argType->getConstantStrings() as $constantStringType) { |
63 | 61 | $serviceId = $constantStringType->getValue(); |
64 | 62 | $service = $this->serviceMap->getService($serviceId); |
65 | | - $types[] = new ConstantBooleanType($service !== null); |
| 63 | + if (!$this->containerHasAlwaysTrue && $service !== null) { |
| 64 | + $types[] = new BooleanType(); |
| 65 | + } else { |
| 66 | + $types[] = new ConstantBooleanType($service !== null); |
| 67 | + } |
66 | 68 | } |
67 | 69 |
|
68 | 70 | return TypeCombinator::union(...$types); |
|
0 commit comments