Skip to content

Commit d773467

Browse files
committed
Avoid phpstan throwing error when variable is passed to factory
eg. Mage::getModel($modelName);
1 parent bf3f95d commit d773467

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Type/Mage/MethodReturnTypeDetector.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpParser\Node\Scalar\String_;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Reflection\MethodReflection;
10-
use PHPStan\ShouldNotHappenException;
10+
use PHPStan\Reflection\ParametersAcceptorSelector;
1111
use PHPStan\Type\ObjectType;
1212
use PHPStan\Type\Type;
1313
use PHPStanMagento1\Config\MagentoCore;
@@ -32,15 +32,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
3232

3333
/**
3434
* @param MethodCall|\PhpParser\Node\Expr\StaticCall $methodCall
35-
* @throws \PHPStan\ShouldNotHappenException
3635
*/
3736
protected function getTypeFromExpr(MethodReflection $methodReflection, $methodCall, Scope $scope): Type
3837
{
39-
if (! isset($methodCall->args[0]) || ! $methodCall->args[0]->value instanceof String_) {
40-
throw new ShouldNotHappenException("type:" . \get_class($methodCall->args[0]->value));
38+
$argument = $methodCall->getArgs()[0] ?? null;
39+
if ($argument === null || ! $argument->value instanceof String_) {
40+
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
4141
}
4242

43-
$modelName = $methodCall->args[0]->value->value;
43+
$modelName = $argument->value->value;
4444
$modelClassName = $this->getMagentoClassName($modelName);
4545

4646
return new ObjectType($modelClassName);

0 commit comments

Comments
 (0)