|
2 | 2 |
|
3 | 3 | namespace PHPStan\Type; |
4 | 4 |
|
| 5 | +use PHPStan\Internal\CombinationsHelper; |
5 | 6 | use PHPStan\Php\PhpVersion; |
6 | 7 | use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode; |
7 | 8 | use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; |
8 | 9 | use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; |
9 | 10 | use PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode; |
10 | 11 | use PHPStan\PhpDocParser\Ast\Type\TypeNode; |
| 12 | +use PHPStan\Reflection\Callables\CallableParametersAcceptor; |
11 | 13 | use PHPStan\Reflection\ClassConstantReflection; |
12 | 14 | use PHPStan\Reflection\ClassMemberAccessAnswerer; |
13 | 15 | use PHPStan\Reflection\ExtendedMethodReflection; |
|
16 | 18 | use PHPStan\Reflection\MissingConstantFromReflectionException; |
17 | 19 | use PHPStan\Reflection\MissingMethodFromReflectionException; |
18 | 20 | use PHPStan\Reflection\MissingPropertyFromReflectionException; |
| 21 | +use PHPStan\Reflection\ParametersAcceptorSelector; |
19 | 22 | use PHPStan\Reflection\TrivialParametersAcceptor; |
20 | 23 | use PHPStan\Reflection\Type\IntersectionTypeUnresolvedMethodPrototypeReflection; |
21 | 24 | use PHPStan\Reflection\Type\IntersectionTypeUnresolvedPropertyPrototypeReflection; |
@@ -1131,11 +1134,34 @@ public function isCallable(): TrinaryLogic |
1131 | 1134 |
|
1132 | 1135 | public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array |
1133 | 1136 | { |
1134 | | - if ($this->isCallable()->no()) { |
1135 | | - throw new ShouldNotHappenException(); |
| 1137 | + $yesAcceptors = []; |
| 1138 | + |
| 1139 | + foreach ($this->types as $type) { |
| 1140 | + if (!$type->isCallable()->yes()) { |
| 1141 | + continue; |
| 1142 | + } |
| 1143 | + $yesAcceptors[] = $type->getCallableParametersAcceptors($scope); |
| 1144 | + } |
| 1145 | + |
| 1146 | + if (count($yesAcceptors) === 0) { |
| 1147 | + if ($this->isCallable()->no()) { |
| 1148 | + throw new ShouldNotHappenException(); |
| 1149 | + } |
| 1150 | + |
| 1151 | + return [new TrivialParametersAcceptor()]; |
| 1152 | + } |
| 1153 | + |
| 1154 | + $result = []; |
| 1155 | + $combinations = CombinationsHelper::combinations($yesAcceptors); |
| 1156 | + foreach ($combinations as $combination) { |
| 1157 | + $combined = ParametersAcceptorSelector::combineAcceptors($combination); |
| 1158 | + if (!$combined instanceof CallableParametersAcceptor) { |
| 1159 | + throw new ShouldNotHappenException(); |
| 1160 | + } |
| 1161 | + $result[] = $combined; |
1136 | 1162 | } |
1137 | 1163 |
|
1138 | | - return [new TrivialParametersAcceptor()]; |
| 1164 | + return $result; |
1139 | 1165 | } |
1140 | 1166 |
|
1141 | 1167 | public function isCloneable(): TrinaryLogic |
|
0 commit comments