mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-30 04:39:01 +01:00
fix: defensive safety against nulls
This commit is contained in:
parent
3c837c25e3
commit
f996f4d559
@ -52,6 +52,10 @@ final class RelationReturnTypeProvider implements MethodReturnTypeProviderInterf
|
||||
|
||||
// If this method name is on the builder object, proxy it over there
|
||||
if ($source->getCodebase()->methods->methodExists(new MethodIdentifier(Builder::class, $method_name_lowercase))) {
|
||||
if (!$template_type_parameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$fake_method_call = new MethodCall(
|
||||
new \PhpParser\Node\Expr\Variable('builder'),
|
||||
$method_name_lowercase,
|
||||
@ -65,8 +69,12 @@ final class RelationReturnTypeProvider implements MethodReturnTypeProviderInterf
|
||||
|
||||
$type = self::executeFakeCall($source, $fake_method_call, $context, $templateType->getKey());
|
||||
|
||||
if (!$type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($type->getAtomicTypes() as $type) {
|
||||
if ($type->value === Builder::class) {
|
||||
if ($type instanceof Type\Atomic\TNamedObject && $type->value === Builder::class) {
|
||||
// ta-da. now we return "this" relation instance
|
||||
return new Union([
|
||||
new Type\Atomic\TGenericObject($fq_classlike_name, $template_type_parameters),
|
||||
|
Loading…
Reference in New Issue
Block a user