|
7 | 7 | use PhpParser\Node\Expr\New_; |
8 | 8 | use PhpParser\Node\Expr\StaticCall; |
9 | 9 | use PHPStan\Analyser\Scope; |
| 10 | +use PHPStan\Analyser\SpecifiedTypes; |
| 11 | +use PHPStan\Analyser\TypeSpecifier; |
| 12 | +use PHPStan\Analyser\TypeSpecifierAwareExtension; |
| 13 | +use PHPStan\Analyser\TypeSpecifierContext; |
10 | 14 | use PHPStan\Reflection\Dummy\ChangedTypeMethodReflection; |
11 | 15 | use PHPStan\Reflection\MethodReflection; |
12 | 16 | use PHPStan\Reflection\ParametersAcceptorSelector; |
|
18 | 22 | use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; |
19 | 23 | use PHPStan\Type\IntegerType; |
20 | 24 | use PHPStan\Type\IntersectionType; |
| 25 | +use PHPStan\Type\MethodTypeSpecifyingExtension; |
21 | 26 | use PHPStan\Type\NeverType; |
22 | 27 | use PHPStan\Type\ObjectType; |
23 | 28 | use PHPStan\Type\ObjectWithoutClassType; |
@@ -299,3 +304,34 @@ public function getTypeFromStaticMethodCall( |
299 | 304 | return $scope->getType(new New_($methodCall->class)); |
300 | 305 | } |
301 | 306 | } |
| 307 | + |
| 308 | +class Bug7385MethodTypeSpecifyingExtension implements TypeSpecifierAwareExtension, MethodTypeSpecifyingExtension |
| 309 | +{ |
| 310 | + public function getClass(): string |
| 311 | + { |
| 312 | + return \Bug7385\Model::class; |
| 313 | + } |
| 314 | + |
| 315 | + public function isMethodSupported(MethodReflection $methodReflection, MethodCall $methodCall = null, TypeSpecifierContext $context = null): bool |
| 316 | + { |
| 317 | + return $methodReflection->getName() === 'assertHasIface'; |
| 318 | + } |
| 319 | + |
| 320 | + /** @var TypeSpecifier */ |
| 321 | + protected $typeSpecifier; |
| 322 | + |
| 323 | + public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void |
| 324 | + { |
| 325 | + $this->typeSpecifier = $typeSpecifier; |
| 326 | + } |
| 327 | + |
| 328 | + public function specifyTypes(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes |
| 329 | + { |
| 330 | + $type = TypeCombinator::intersect( |
| 331 | + $scope->getType($methodCall->var), |
| 332 | + new ObjectType(\Bug7385\Iface::class) |
| 333 | + ); |
| 334 | + |
| 335 | + return $this->typeSpecifier->create($methodCall->var, $type, TypeSpecifierContext::createNull()); |
| 336 | + } |
| 337 | +} |
0 commit comments