Skip to content

Commit d21c36a

Browse files
committed
feat: use class-strings instead of imports
1 parent 3450677 commit d21c36a

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/Extensions/Contracts/Container/ContainerDynamicReturnType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Recoded\PHPStanLaravel\Extensions\Contracts\Container;
66

7-
use Illuminate\Contracts\Container\Container;
87
use PhpParser\Node\Expr\MethodCall;
98
use PHPStan\Analyser\Scope;
109
use PHPStan\Reflection\MethodReflection;
@@ -24,7 +23,7 @@ public function __construct(private DependencyRegistry $dependencyRegistry)
2423

2524
public function getClass(): string
2625
{
27-
return Container::class;
26+
return 'Illuminate\Contracts\Container\Container';
2827
}
2928

3029
public function isMethodSupported(MethodReflection $methodReflection): bool

src/Extensions/Eloquent/BuilderCollectionDynamicReturnType.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Recoded\PHPStanLaravel\Extensions\Eloquent;
66

7-
use Illuminate\Contracts\Database\Eloquent\Builder;
87
use PhpParser\Node\Expr\MethodCall;
98
use PHPStan\Analyser\Scope;
109
use PHPStan\Reflection\MethodReflection;
@@ -20,14 +19,14 @@ final class BuilderCollectionDynamicReturnType implements DynamicMethodReturnTyp
2019
{
2120
public function getClass(): string
2221
{
23-
return Builder::class;
22+
return 'Illuminate\Contracts\Database\Eloquent\Builder';
2423
}
2524

2625
public function isMethodSupported(MethodReflection $methodReflection): bool
2726
{
2827
$modelType = $methodReflection
2928
->getDeclaringClass()
30-
->getAncestorWithClassName(Builder::class)
29+
->getAncestorWithClassName('Illuminate\Contracts\Database\Eloquent\Builder')
3130
?->getActiveTemplateTypeMap()
3231
->getType('TModel');
3332

@@ -60,7 +59,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
6059
/** @var \PHPStan\Type\ObjectType $modelType */
6160
$modelType = $methodReflection
6261
->getDeclaringClass()
63-
->getAncestorWithClassName(Builder::class)
62+
->getAncestorWithClassName('Illuminate\Contracts\Database\Eloquent\Builder')
6463
?->getActiveTemplateTypeMap()
6564
->getType('TModel');
6665

src/Extensions/Eloquent/Scopes.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Recoded\PHPStanLaravel\Extensions\Eloquent;
66

7-
use Illuminate\Contracts\Database\Eloquent\Builder;
8-
use Illuminate\Database\Eloquent\Model;
97
use PHPStan\Analyser\OutOfClassScope;
108
use PHPStan\Reflection\ClassReflection;
119
use PHPStan\Reflection\MethodReflection;
@@ -18,15 +16,15 @@ final class Scopes implements MethodsClassReflectionExtension
1816
{
1917
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
2018
{
21-
$builderReflection = $classReflection->getAncestorWithClassName(Builder::class);
19+
$builderReflection = $classReflection->getAncestorWithClassName('Illuminate\Contracts\Database\Eloquent\Builder');
2220

2321
if ($builderReflection === null) {
2422
return false;
2523
}
2624

2725
$modelClass = $builderReflection->getActiveTemplateTypeMap()->getType('TModel');
2826

29-
if ($modelClass === null || !(new ObjectType(Model::class))->isSuperTypeOf($modelClass)->yes()) {
27+
if ($modelClass === null || !(new ObjectType('Illuminate\Database\Eloquent\Model'))->isSuperTypeOf($modelClass)->yes()) {
3028
return false;
3129
}
3230

@@ -43,13 +41,13 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
4341

4442
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
4543
{
46-
$builderReflection = $classReflection->getAncestorWithClassName(Builder::class);
44+
$builderReflection = $classReflection->getAncestorWithClassName('Illuminate\Contracts\Database\Eloquent\Builder');
4745

4846
Assert::notNull($builderReflection);
4947

5048
$modelClass = $builderReflection->getActiveTemplateTypeMap()->getType('TModel');
5149

52-
if ($modelClass === null || !(new ObjectType(Model::class))->isSuperTypeOf($modelClass)->yes()) {
50+
if ($modelClass === null || !(new ObjectType('Illuminate\Database\Eloquent\Model'))->isSuperTypeOf($modelClass)->yes()) {
5351
throw new ShouldNotHappenException();
5452
}
5553

0 commit comments

Comments
 (0)