|
66 | 66 | use PHPStan\DependencyInjection\AutowiredParameter;
|
67 | 67 | use PHPStan\DependencyInjection\AutowiredService;
|
68 | 68 | use PHPStan\DependencyInjection\Reflection\ClassReflectionExtensionRegistryProvider;
|
| 69 | +use PHPStan\DependencyInjection\Type\DynamicParameterTypeExtensionProvider; |
69 | 70 | use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
|
70 | 71 | use PHPStan\DependencyInjection\Type\ParameterClosureThisExtensionProvider;
|
71 | 72 | use PHPStan\DependencyInjection\Type\ParameterClosureTypeExtensionProvider;
|
@@ -274,6 +275,7 @@ public function __construct(
|
274 | 275 | private readonly DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
|
275 | 276 | private readonly ReadWritePropertiesExtensionProvider $readWritePropertiesExtensionProvider,
|
276 | 277 | private readonly ParameterClosureThisExtensionProvider $parameterClosureThisExtensionProvider,
|
| 278 | + private readonly DynamicParameterTypeExtensionProvider $dynamicParameterTypeExtensionProvider, |
277 | 279 | private readonly ParameterClosureTypeExtensionProvider $parameterClosureTypeExtensionProvider,
|
278 | 280 | private readonly ScopeFactory $scopeFactory,
|
279 | 281 | #[AutowiredParameter]
|
@@ -5224,7 +5226,8 @@ private function processArgs(
|
5224 | 5226 | }
|
5225 | 5227 |
|
5226 | 5228 | if ($parameter !== null) {
|
5227 |
| - $overwritingParameterType = $this->getParameterTypeFromParameterClosureTypeExtension($callLike, $calleeReflection, $parameter, $scopeToPass); |
| 5229 | + $overwritingParameterType = $this->getParameterTypeFromDynamicParameterTypeExtension($callLike, $calleeReflection, $parameter, $scopeToPass) |
| 5230 | + ?? $this->getParameterTypeFromParameterClosureTypeExtension($callLike, $calleeReflection, $parameter, $scopeToPass); |
5228 | 5231 |
|
5229 | 5232 | if ($overwritingParameterType !== null) {
|
5230 | 5233 | $parameterType = $overwritingParameterType;
|
@@ -5279,7 +5282,8 @@ private function processArgs(
|
5279 | 5282 | }
|
5280 | 5283 |
|
5281 | 5284 | if ($parameter !== null) {
|
5282 |
| - $overwritingParameterType = $this->getParameterTypeFromParameterClosureTypeExtension($callLike, $calleeReflection, $parameter, $scopeToPass); |
| 5285 | + $overwritingParameterType = $this->getParameterTypeFromDynamicParameterTypeExtension($callLike, $calleeReflection, $parameter, $scopeToPass) |
| 5286 | + ?? $this->getParameterTypeFromParameterClosureTypeExtension($callLike, $calleeReflection, $parameter, $scopeToPass); |
5283 | 5287 |
|
5284 | 5288 | if ($overwritingParameterType !== null) {
|
5285 | 5289 | $parameterType = $overwritingParameterType;
|
@@ -5428,6 +5432,46 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
|
5428 | 5432 | return new ExpressionResult($scope, $hasYield, $isAlwaysTerminating, $throwPoints, $impurePoints);
|
5429 | 5433 | }
|
5430 | 5434 |
|
| 5435 | + /** |
| 5436 | + * @param MethodReflection|FunctionReflection|null $calleeReflection |
| 5437 | + */ |
| 5438 | + private function getParameterTypeFromDynamicParameterTypeExtension(CallLike $callLike, $calleeReflection, ParameterReflection $parameter, MutatingScope $scope): ?Type |
| 5439 | + { |
| 5440 | + if ($callLike instanceof FuncCall && $calleeReflection instanceof FunctionReflection) { |
| 5441 | + foreach ($this->dynamicParameterTypeExtensionProvider->getDynamicFunctionParameterTypeExtensions() as $dynamicFunctionParameterTypeExtension) { |
| 5442 | + if (!$dynamicFunctionParameterTypeExtension->isFunctionSupported($calleeReflection, $parameter)) { |
| 5443 | + continue; |
| 5444 | + } |
| 5445 | + $type = $dynamicFunctionParameterTypeExtension->getTypeFromFunctionCall($calleeReflection, $callLike, $parameter, $scope); |
| 5446 | + if ($type !== null) { |
| 5447 | + return $type; |
| 5448 | + } |
| 5449 | + } |
| 5450 | + } elseif ($callLike instanceof StaticCall && $calleeReflection instanceof MethodReflection) { |
| 5451 | + foreach ($this->dynamicParameterTypeExtensionProvider->getDynamicStaticMethodParameterTypeExtensions() as $dynamicStaticMethodParameterTypeExtension) { |
| 5452 | + if (!$dynamicStaticMethodParameterTypeExtension->isStaticMethodSupported($calleeReflection, $parameter)) { |
| 5453 | + continue; |
| 5454 | + } |
| 5455 | + $type = $dynamicStaticMethodParameterTypeExtension->getTypeFromStaticMethodCall($calleeReflection, $callLike, $parameter, $scope); |
| 5456 | + if ($type !== null) { |
| 5457 | + return $type; |
| 5458 | + } |
| 5459 | + } |
| 5460 | + } elseif ($callLike instanceof MethodCall && $calleeReflection instanceof MethodReflection) { |
| 5461 | + foreach ($this->dynamicParameterTypeExtensionProvider->getDynamicMethodParameterTypeExtensions() as $dynamicMethodParameterTypeExtension) { |
| 5462 | + if (!$dynamicMethodParameterTypeExtension->isMethodSupported($calleeReflection, $parameter)) { |
| 5463 | + continue; |
| 5464 | + } |
| 5465 | + $type = $dynamicMethodParameterTypeExtension->getTypeFromMethodCall($calleeReflection, $callLike, $parameter, $scope); |
| 5466 | + if ($type !== null) { |
| 5467 | + return $type; |
| 5468 | + } |
| 5469 | + } |
| 5470 | + } |
| 5471 | + |
| 5472 | + return null; |
| 5473 | + } |
| 5474 | + |
5431 | 5475 | /**
|
5432 | 5476 | * @param MethodReflection|FunctionReflection|null $calleeReflection
|
5433 | 5477 | */
|
|
0 commit comments