Skip to content

Commit 28d7065

Browse files
committed
Merge branch 2.1.x into 2.2.x
2 parents 94bbb6d + 3a4c0e2 commit 28d7065

File tree

3 files changed

+43
-57
lines changed

3 files changed

+43
-57
lines changed

src/Analyser/ExprHandler/FuncCallHandler.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -484,28 +484,21 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
484484
private function getFunctionThrowPoint(
485485
FunctionReflection $functionReflection,
486486
?ParametersAcceptor $parametersAcceptor,
487-
FuncCall $funcCall,
487+
FuncCall $normalizedFuncCall,
488488
MutatingScope $scope,
489489
): ?InternalThrowPoint
490490
{
491-
$normalizedFuncCall = $funcCall;
492-
if ($parametersAcceptor !== null) {
493-
$normalizedFuncCall = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $funcCall);
494-
}
495-
496-
if ($normalizedFuncCall !== null) {
497-
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicFunctionThrowTypeExtensions() as $extension) {
498-
if (!$extension->isFunctionSupported($functionReflection)) {
499-
continue;
500-
}
501-
502-
$throwType = $extension->getThrowTypeFromFunctionCall($functionReflection, $normalizedFuncCall, $scope);
503-
if ($throwType === null) {
504-
return null;
505-
}
491+
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicFunctionThrowTypeExtensions() as $extension) {
492+
if (!$extension->isFunctionSupported($functionReflection)) {
493+
continue;
494+
}
506495

507-
return InternalThrowPoint::createExplicit($scope, $throwType, $funcCall, false);
496+
$throwType = $extension->getThrowTypeFromFunctionCall($functionReflection, $normalizedFuncCall, $scope);
497+
if ($throwType === null) {
498+
return null;
508499
}
500+
501+
return InternalThrowPoint::createExplicit($scope, $throwType, $normalizedFuncCall, false);
509502
}
510503

511504
$throwType = $functionReflection->getThrowType();
@@ -518,7 +511,7 @@ private function getFunctionThrowPoint(
518511

519512
if ($throwType !== null) {
520513
if (!$throwType->isVoid()->yes()) {
521-
return InternalThrowPoint::createExplicit($scope, $throwType, $funcCall, true);
514+
return InternalThrowPoint::createExplicit($scope, $throwType, $normalizedFuncCall, true);
522515
}
523516
} elseif ($this->implicitThrows) {
524517
$requiredParameters = null;
@@ -536,11 +529,11 @@ private function getFunctionThrowPoint(
536529
!$functionReflection->isBuiltin()
537530
|| $requiredParameters === null
538531
|| $requiredParameters > 0
539-
|| count($funcCall->getArgs()) > 0
532+
|| count($normalizedFuncCall->getArgs()) > 0
540533
) {
541-
$functionReturnedType = $scope->getType($funcCall);
534+
$functionReturnedType = $scope->getType($normalizedFuncCall);
542535
if (!(new ObjectType(Throwable::class))->isSuperTypeOf($functionReturnedType)->yes()) {
543-
return InternalThrowPoint::createImplicit($scope, $funcCall);
536+
return InternalThrowPoint::createImplicit($scope, $normalizedFuncCall);
544537
}
545538
}
546539
}

src/Analyser/ExprHandler/MethodCallHandler.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
153153
$scope = $argsResult->getScope();
154154

155155
if ($methodReflection !== null) {
156-
$methodThrowPoint = $this->getMethodThrowPoint($methodReflection, $parametersAcceptor, $expr, $scope);
156+
$methodThrowPoint = $this->getMethodThrowPoint($methodReflection, $parametersAcceptor, $normalizedExpr, $scope);
157157
if ($methodThrowPoint !== null) {
158158
$throwPoints[] = $methodThrowPoint;
159159
}
@@ -235,29 +235,26 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
235235
return $result;
236236
}
237237

238-
private function getMethodThrowPoint(MethodReflection $methodReflection, ParametersAcceptor $parametersAcceptor, MethodCall $methodCall, MutatingScope $scope): ?InternalThrowPoint
238+
private function getMethodThrowPoint(MethodReflection $methodReflection, ParametersAcceptor $parametersAcceptor, MethodCall $normalizedMethodCall, MutatingScope $scope): ?InternalThrowPoint
239239
{
240-
$normalizedMethodCall = ArgumentsNormalizer::reorderMethodArguments($parametersAcceptor, $methodCall);
241-
if ($normalizedMethodCall !== null) {
242-
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicMethodThrowTypeExtensions() as $extension) {
243-
if (!$extension->isMethodSupported($methodReflection)) {
244-
continue;
245-
}
246-
247-
$throwType = $extension->getThrowTypeFromMethodCall($methodReflection, $normalizedMethodCall, $scope);
248-
if ($throwType === null) {
249-
return null;
250-
}
240+
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicMethodThrowTypeExtensions() as $extension) {
241+
if (!$extension->isMethodSupported($methodReflection)) {
242+
continue;
243+
}
251244

252-
return InternalThrowPoint::createExplicit($scope, $throwType, $methodCall, false);
245+
$throwType = $extension->getThrowTypeFromMethodCall($methodReflection, $normalizedMethodCall, $scope);
246+
if ($throwType === null) {
247+
return null;
253248
}
249+
250+
return InternalThrowPoint::createExplicit($scope, $throwType, $normalizedMethodCall, false);
254251
}
255252

256253
if (
257254
in_array($methodReflection->getName(), ['invoke', 'invokeArgs'], true)
258255
&& in_array($methodReflection->getDeclaringClass()->getName(), [ReflectionMethod::class, ReflectionFunction::class], true)
259256
) {
260-
return InternalThrowPoint::createImplicit($scope, $methodCall);
257+
return InternalThrowPoint::createImplicit($scope, $normalizedMethodCall);
261258
}
262259

263260
$throwType = $methodReflection->getThrowType();
@@ -270,12 +267,12 @@ private function getMethodThrowPoint(MethodReflection $methodReflection, Paramet
270267

271268
if ($throwType !== null) {
272269
if (!$throwType->isVoid()->yes()) {
273-
return InternalThrowPoint::createExplicit($scope, $throwType, $methodCall, true);
270+
return InternalThrowPoint::createExplicit($scope, $throwType, $normalizedMethodCall, true);
274271
}
275272
} elseif ($this->implicitThrows) {
276-
$methodReturnedType = $scope->getType($methodCall);
273+
$methodReturnedType = $scope->getType($normalizedMethodCall);
277274
if (!(new ObjectType(Throwable::class))->isSuperTypeOf($methodReturnedType)->yes()) {
278-
return InternalThrowPoint::createImplicit($scope, $methodCall);
275+
return InternalThrowPoint::createImplicit($scope, $normalizedMethodCall);
279276
}
280277
}
281278

src/Analyser/ExprHandler/StaticCallHandler.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use PHPStan\Node\Expr\PossiblyImpureCallExpr;
3030
use PHPStan\Reflection\Callables\SimpleImpurePoint;
3131
use PHPStan\Reflection\MethodReflection;
32-
use PHPStan\Reflection\ParametersAcceptor;
3332
use PHPStan\Reflection\ParametersAcceptorSelector;
3433
use PHPStan\Type\ErrorType;
3534
use PHPStan\Type\MixedType;
@@ -199,7 +198,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
199198
$scopeFunction = $scope->getFunction();
200199

201200
if ($methodReflection !== null) {
202-
$methodThrowPoint = $this->getStaticMethodThrowPoint($methodReflection, $parametersAcceptor, $expr, $scope);
201+
$methodThrowPoint = $this->getStaticMethodThrowPoint($methodReflection, $normalizedExpr, $scope);
203202
if ($methodThrowPoint !== null) {
204203
$throwPoints[] = $methodThrowPoint;
205204
}
@@ -269,33 +268,30 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
269268
);
270269
}
271270

272-
private function getStaticMethodThrowPoint(MethodReflection $methodReflection, ParametersAcceptor $parametersAcceptor, StaticCall $methodCall, MutatingScope $scope): ?InternalThrowPoint
271+
private function getStaticMethodThrowPoint(MethodReflection $methodReflection, StaticCall $normalizedMethodCall, MutatingScope $scope): ?InternalThrowPoint
273272
{
274-
$normalizedMethodCall = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $methodCall);
275-
if ($normalizedMethodCall !== null) {
276-
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicStaticMethodThrowTypeExtensions() as $extension) {
277-
if (!$extension->isStaticMethodSupported($methodReflection)) {
278-
continue;
279-
}
280-
281-
$throwType = $extension->getThrowTypeFromStaticMethodCall($methodReflection, $normalizedMethodCall, $scope);
282-
if ($throwType === null) {
283-
return null;
284-
}
273+
foreach ($this->dynamicThrowTypeExtensionProvider->getDynamicStaticMethodThrowTypeExtensions() as $extension) {
274+
if (!$extension->isStaticMethodSupported($methodReflection)) {
275+
continue;
276+
}
285277

286-
return InternalThrowPoint::createExplicit($scope, $throwType, $methodCall, false);
278+
$throwType = $extension->getThrowTypeFromStaticMethodCall($methodReflection, $normalizedMethodCall, $scope);
279+
if ($throwType === null) {
280+
return null;
287281
}
282+
283+
return InternalThrowPoint::createExplicit($scope, $throwType, $normalizedMethodCall, false);
288284
}
289285

290286
if ($methodReflection->getThrowType() !== null) {
291287
$throwType = $methodReflection->getThrowType();
292288
if (!$throwType->isVoid()->yes()) {
293-
return InternalThrowPoint::createExplicit($scope, $throwType, $methodCall, true);
289+
return InternalThrowPoint::createExplicit($scope, $throwType, $normalizedMethodCall, true);
294290
}
295291
} elseif ($this->implicitThrows) {
296-
$methodReturnedType = $scope->getType($methodCall);
292+
$methodReturnedType = $scope->getType($normalizedMethodCall);
297293
if (!(new ObjectType(Throwable::class))->isSuperTypeOf($methodReturnedType)->yes()) {
298-
return InternalThrowPoint::createImplicit($scope, $methodCall);
294+
return InternalThrowPoint::createImplicit($scope, $normalizedMethodCall);
299295
}
300296
}
301297

0 commit comments

Comments
 (0)