Skip to content

Commit

Permalink
Merge pull request #15 from calebdw/relation_class_forwarding
Browse files Browse the repository at this point in the history
fix: relation class forwarding
  • Loading branch information
calebdw authored Sep 14, 2024
2 parents 9844f3e + f0b347b commit 07b0e17
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Methods/EloquentBuilderForwardsCallsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
*/
private function findMethod(ClassReflection $classReflection, string $methodName): MethodReflection|null
{
if ($classReflection->getName() !== EloquentBuilder::class && ! $classReflection->isSubclassOf(EloquentBuilder::class)) {
if (! $classReflection->is(EloquentBuilder::class)) {
return null;
}

Expand Down
5 changes: 2 additions & 3 deletions src/Methods/MacroMethodsClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
}
} elseif (
$this->hasIndirectTraitUse($classReflection, Macroable::class) ||
$classReflection->getName() === Builder::class ||
$classReflection->isSubclassOf(Builder::class) ||
$classReflection->getName() === QueryBuilder::class
$classReflection->is(Builder::class) ||
$classReflection->is(QueryBuilder::class)
) {
$classNames = [$classReflection->getName()];
$macroTraitProperty = 'macros';
Expand Down
2 changes: 1 addition & 1 deletion src/Methods/ModelForwardsCallsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
*/
private function findMethod(ClassReflection $classReflection, string $methodName): MethodReflection|null
{
if ($classReflection->getName() !== Model::class && ! $classReflection->isSubclassOf(Model::class)) {
if (! $classReflection->is(Model::class)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Methods/RelationForwardsCallsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getMethod(
*/
private function findMethod(ClassReflection $classReflection, string $methodName): MethodReflection|null
{
if (! $classReflection->isSubclassOf(Relation::class)) {
if (! $classReflection->is(Relation::class)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Support/CollectionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private function getTypeFromEloquentCollection(ClassReflection $classReflection)

$innerValueType = $classReflection->getActiveTemplateTypeMap()->getType('TModel');

if ($classReflection->getName() === EloquentCollection::class || $classReflection->isSubclassOf(EloquentCollection::class)) {
if ($classReflection->is(EloquentCollection::class)) {
$keyType = new IntegerType();
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Type/data/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Foundation\Http\FormRequest;

use function PHPStan\Testing\assertType;
Expand Down Expand Up @@ -129,6 +130,9 @@ function test(
assertType('App\User|null', User::firstWhere(['email' => '[email protected]']));
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $user->with('accounts'));
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $user->with('accounts')->with('group'));
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $user->with(['accounts' => function (Relation $relation) {
assertType('Illuminate\Database\Eloquent\Relations\Relation<Illuminate\Database\Eloquent\Model>', $relation->orderBy('id'));
}]));
assertType('Illuminate\Database\Eloquent\Builder<App\User>', User::lockForUpdate());
assertType('Illuminate\Database\Eloquent\Builder<App\User>', User::sharedLock());
assertType('Illuminate\Database\Eloquent\Builder<App\User>', User::query());
Expand Down

0 comments on commit 07b0e17

Please sign in to comment.