Skip to content

Commit

Permalink
Avoid phpstan throwing error when variable is passed to factory
Browse files Browse the repository at this point in the history
eg. Mage::getModel($modelName);
  • Loading branch information
tmotyl committed Mar 5, 2022
1 parent bf3f95d commit d773467
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Type/Mage/MethodReturnTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStanMagento1\Config\MagentoCore;
Expand All @@ -32,15 +32,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method

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

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

return new ObjectType($modelClassName);
Expand Down

0 comments on commit d773467

Please sign in to comment.