Skip to content

Commit 7a9bd2f

Browse files
committed
fix: use scope to get the correct type in ConvertEnumerableToArrayToAllRector
1 parent 7e07220 commit 7a9bd2f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Rector/MethodCall/ConvertEnumerableToArrayToAllRector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Identifier;
1111
use PHPStan\Type\ObjectType;
1212
use PHPStan\Type\TypeCombinator;
13+
use Rector\PHPStan\ScopeFetcher;
1314
use RectorLaravel\AbstractRector;
1415
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1516
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -62,7 +63,12 @@ public function refactor(Node $node): ?Node
6263
return null;
6364
}
6465

65-
$type = TypeCombinator::removeNull($this->getType($node->var));
66+
$scope = ScopeFetcher::fetch($node);
67+
$type = TypeCombinator::removeNull(
68+
// This HAS to use the $scope->getType() as opposed to $this->getType()
69+
// because it's not getting the proper type from the Larastan extensions
70+
$scope->getType($node->var)
71+
);
6672
$valueType = $type->getTemplateType('Illuminate\Support\Enumerable', 'TValue');
6773

6874
if (! (new ObjectType('Illuminate\Contracts\Support\Arrayable'))->isSuperTypeOf($valueType)->no()) {

0 commit comments

Comments
 (0)