Skip to content

Commit

Permalink
AddGenericReturnTypeToRelationsRector fix for chained relation call
Browse files Browse the repository at this point in the history
  • Loading branch information
rudiedirkx committed Dec 17, 2024
1 parent 44674a8 commit 4061832
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ private function getRelationMethodCall(ClassMethod $classMethod): ?MethodCall
return null;
}

// Find deepest MethodCall, which is the first in code, to allow chaining:
// $this->hasMany(..)->orderBy(..)->with(..)
while ($methodCall->var instanceof MethodCall) {
$methodCall = $methodCall->var;
}

// Called method should be one of the Laravel's relation methods
if (! $this->doesMethodHasName($methodCall, self::RELATION_METHODS)) {
return null;
Expand Down

0 comments on commit 4061832

Please sign in to comment.