1414use PHPStan \Analyser \ExpressionResultStorage ;
1515use PHPStan \Analyser \ExprHandler ;
1616use PHPStan \Analyser \ExprHandler \Helper \MethodCallReturnTypeHelper ;
17+ use PHPStan \Analyser \ExprHandler \Helper \MethodThrowPointHelper ;
1718use PHPStan \Analyser \ExprHandler \Helper \NullsafeShortCircuitingHelper ;
1819use PHPStan \Analyser \ImpurePoint ;
1920use PHPStan \Analyser \InternalThrowPoint ;
2021use PHPStan \Analyser \MutatingScope ;
2122use PHPStan \Analyser \NodeScopeResolver ;
2223use PHPStan \DependencyInjection \AutowiredParameter ;
2324use PHPStan \DependencyInjection \AutowiredService ;
24- use PHPStan \DependencyInjection \Type \DynamicThrowTypeExtensionProvider ;
2525use PHPStan \Node \Expr \PossiblyImpureCallExpr ;
2626use PHPStan \Node \InvalidateExprNode ;
2727use PHPStan \Reflection \Callables \SimpleImpurePoint ;
2828use PHPStan \Reflection \ExtendedParametersAcceptor ;
29- use PHPStan \Reflection \MethodReflection ;
30- use PHPStan \Reflection \ParametersAcceptor ;
3129use PHPStan \Reflection \ParametersAcceptorSelector ;
3230use PHPStan \Type \ErrorType ;
3331use PHPStan \Type \Generic \TemplateTypeHelper ;
3432use PHPStan \Type \Generic \TemplateTypeVariance ;
3533use PHPStan \Type \Generic \TemplateTypeVarianceMap ;
3634use PHPStan \Type \MixedType ;
3735use PHPStan \Type \NeverType ;
38- use PHPStan \Type \ObjectType ;
3936use PHPStan \Type \Type ;
4037use PHPStan \Type \TypeCombinator ;
4138use PHPStan \Type \TypeUtils ;
42- use ReflectionFunction ;
43- use ReflectionMethod ;
44- use Throwable ;
4539use function array_map ;
4640use function array_merge ;
4741use function count ;
48- use function in_array ;
4942use function sprintf ;
5043use function strtolower ;
5144
@@ -57,10 +50,8 @@ final class MethodCallHandler implements ExprHandler
5750{
5851
5952 public function __construct (
60- private DynamicThrowTypeExtensionProvider $ dynamicThrowTypeExtensionProvider ,
6153 private MethodCallReturnTypeHelper $ methodCallReturnTypeHelper ,
62- #[AutowiredParameter(ref: '%exceptions.implicitThrows% ' )]
63- private bool $ implicitThrows ,
54+ private MethodThrowPointHelper $ methodThrowPointHelper ,
6455 #[AutowiredParameter]
6556 private bool $ rememberPossiblyImpureFunctionValues ,
6657 )
@@ -153,7 +144,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
153144 $ scope = $ argsResult ->getScope ();
154145
155146 if ($ methodReflection !== null ) {
156- $ methodThrowPoint = $ this ->getMethodThrowPoint ($ methodReflection , $ parametersAcceptor , $ normalizedExpr , $ scope );
147+ $ methodThrowPoint = $ this ->methodThrowPointHelper -> getThrowPoint ($ methodReflection , $ parametersAcceptor , $ normalizedExpr , $ scope );
157148 if ($ methodThrowPoint !== null ) {
158149 $ throwPoints [] = $ methodThrowPoint ;
159150 }
@@ -235,50 +226,6 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
235226 return $ result ;
236227 }
237228
238- private function getMethodThrowPoint (MethodReflection $ methodReflection , ParametersAcceptor $ parametersAcceptor , MethodCall $ normalizedMethodCall , MutatingScope $ scope ): ?InternalThrowPoint
239- {
240- foreach ($ this ->dynamicThrowTypeExtensionProvider ->getDynamicMethodThrowTypeExtensions () as $ extension ) {
241- if (!$ extension ->isMethodSupported ($ methodReflection )) {
242- continue ;
243- }
244-
245- $ throwType = $ extension ->getThrowTypeFromMethodCall ($ methodReflection , $ normalizedMethodCall , $ scope );
246- if ($ throwType === null ) {
247- return null ;
248- }
249-
250- return InternalThrowPoint::createExplicit ($ scope , $ throwType , $ normalizedMethodCall , false );
251- }
252-
253- if (
254- in_array ($ methodReflection ->getName (), ['invoke ' , 'invokeArgs ' ], true )
255- && in_array ($ methodReflection ->getDeclaringClass ()->getName (), [ReflectionMethod::class, ReflectionFunction::class], true )
256- ) {
257- return InternalThrowPoint::createImplicit ($ scope , $ normalizedMethodCall );
258- }
259-
260- $ throwType = $ methodReflection ->getThrowType ();
261- if ($ throwType === null ) {
262- $ returnType = $ parametersAcceptor ->getReturnType ();
263- if ($ returnType instanceof NeverType && $ returnType ->isExplicit ()) {
264- $ throwType = new ObjectType (Throwable::class);
265- }
266- }
267-
268- if ($ throwType !== null ) {
269- if (!$ throwType ->isVoid ()->yes ()) {
270- return InternalThrowPoint::createExplicit ($ scope , $ throwType , $ normalizedMethodCall , true );
271- }
272- } elseif ($ this ->implicitThrows ) {
273- $ methodReturnedType = $ scope ->getType ($ normalizedMethodCall );
274- if (!(new ObjectType (Throwable::class))->isSuperTypeOf ($ methodReturnedType )->yes ()) {
275- return InternalThrowPoint::createImplicit ($ scope , $ normalizedMethodCall );
276- }
277- }
278-
279- return null ;
280- }
281-
282229 public function resolveType (MutatingScope $ scope , Expr $ expr ): Type
283230 {
284231 if ($ expr ->name instanceof Identifier) {
0 commit comments