-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Feature request
I wrote this extension to have better throws inference from \Ds\Map::get(). I wonder if there's a way to somehow make it into phpstan's core so I don't have to copy this extension into every project?
use Ds\Map;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodThrowTypeExtension;
use PHPStan\Type\Type;
use function count;
final class ExtDsThrowExtension implements DynamicMethodThrowTypeExtension
{
public function isMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getDeclaringClass()->getName() === Map::class
&& $methodReflection->getName() === 'get';
}
public function getThrowTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type|null
{
if (count($methodCall->args) < 2) {
return $methodReflection->getThrowType();
}
return null;
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels