Skip to content

Commit

Permalink
fix: Prevent crash with static call on instances of intersection (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
villfa authored Jul 16, 2023
1 parent 5c3b71c commit a95b5e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MissingMethodFromReflectionException;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
Expand Down Expand Up @@ -102,11 +103,15 @@ public function getTypeFromStaticMethodCall(
$types = [];

foreach ($classNames as $className) {
if ($this->reflectionProvider->hasClass($className)) {
if (! $this->reflectionProvider->hasClass($className)) {
continue;
}
try {
$types[] = new GenericObjectType(
$this->builderHelper->determineBuilderName($className),
[new ObjectType($className)]
);
} catch (MissingMethodFromReflectionException) {
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/Type/data/eloquent-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ function doFoo(User $user, Post $post, $userAndAuth): void
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $userAndAuth->newQueryWithoutScopes());
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $userAndAuth->newQueryWithoutScope('foo'));
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $userAndAuth->newQueryForRestoration([1]));
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $userAndAuth::query());

assertType('Illuminate\Support\LazyCollection<int, App\User>', User::query()->lazy());
assertType('Illuminate\Support\LazyCollection<int, App\User>', User::query()->lazyById());
Expand Down

0 comments on commit a95b5e3

Please sign in to comment.