• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mpyw / laravel-local-class-scope / 27456729495

13 Jun 2026 04:36AM UTC coverage: 92.405% (-7.6%) from 100.0%
27456729495

Pull #11

github

web-flow
Merge 60c68ee8f into 069938011
Pull Request #11: Implement PHPStan extension to get better static analysis support for the `scoped` method

62 of 68 new or added lines in 3 files covered. (91.18%)

73 of 79 relevant lines covered (92.41%)

13.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/src/PHPStan/Reflection/ScopedMacroExtension.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Mpyw\LaravelLocalClassScope\PHPStan\Reflection;
6

7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Model;
9
use Override;
10
use PHPStan\Reflection\ClassReflection;
11
use PHPStan\Reflection\MethodReflection;
12
use PHPStan\Reflection\MethodsClassReflectionExtension;
13
use PHPStan\Type\Generic\GenericObjectType;
14
use PHPStan\Type\ObjectType;
15

16
final class ScopedMacroExtension implements MethodsClassReflectionExtension
17
{
18
    #[Override]
19
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
20
    {
21
        if ($methodName !== 'scoped') {
11✔
22
            return false;
11✔
23
        }
24

25
        return $classReflection->is(Model::class) || $classReflection->is(Builder::class);
11✔
26
    }
27

28
    #[Override]
29
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
30
    {
31
        if ($classReflection->is(Model::class)) {
11✔
32
            // Model::scoped()
33
            $modelType = new ObjectType($classReflection->getName());
11✔
34
            $isStatic  = true;
11✔
35
        } else {
36
            // Builder::scoped()
37
            $templateMap = $classReflection->getActiveTemplateTypeMap();
11✔
38
            $modelType   = $templateMap->getType('TModel');
11✔
39

40
            if ($modelType === null) {
11✔
NEW
41
                $modelType = new ObjectType(Model::class);
×
42
            }
43

44
            $isStatic = false;
11✔
45
        }
46

47
        $builderType = new GenericObjectType(
11✔
48
            Builder::class,
11✔
49
            [$modelType],
11✔
50
        );
11✔
51

52
        return new ScopedMethodReflection(
11✔
53
            $classReflection,
11✔
54
            $builderType,
11✔
55
            $isStatic,
11✔
56
        );
11✔
57
    }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc