Skip to content

Commit e4dcca5

Browse files
committed
refactor: make hasMethod consistent with getMethod for scopes
1 parent 0773ebc commit e4dcca5

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Extensions/Eloquent/Scopes.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,19 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
2626

2727
$modelClass = $builderReflection->getActiveTemplateTypeMap()->getType('TModel');
2828

29-
if (
30-
$modelClass === null
31-
|| !(new ObjectType(Model::class))->isSuperTypeOf($modelClass)->yes()
32-
) {
29+
if ($modelClass === null || !(new ObjectType(Model::class))->isSuperTypeOf($modelClass)->yes()) {
3330
return false;
3431
}
3532

36-
foreach ($modelClass->getObjectClassReflections() as $reflection) {
37-
if (!$reflection->hasMethod('scope' . ucfirst($methodName))) {
38-
return false;
39-
}
33+
/** @var \PHPStan\Type\ObjectType $modelClass */
34+
35+
$reflection = $modelClass->getClassReflection();
36+
37+
if ($reflection === null) {
38+
throw new ShouldNotHappenException();
4039
}
4140

42-
return true;
41+
return $reflection->hasMethod('scope' . ucfirst($methodName));
4342
}
4443

4544
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection

0 commit comments

Comments
 (0)