From 8df702ed06f116cb634f02d1a6994f8660175026 Mon Sep 17 00:00:00 2001 From: Dao Hoang Son Date: Mon, 1 Oct 2018 10:19:26 +0700 Subject: [PATCH] Adjust phpstan entity relation type from Entity -> Entity|null --- Cli/Command/AutoGen.php | 2 +- PHPStan/Reflection/EntityRelationReflection.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cli/Command/AutoGen.php b/Cli/Command/AutoGen.php index 23f2edb..abf4f2c 100644 --- a/Cli/Command/AutoGen.php +++ b/Cli/Command/AutoGen.php @@ -19,7 +19,7 @@ class AutoGen extends Command const MARKER_BEGINS = '// DevHelper/Autogen begins'; const MARKER_ENDS = '// DevHelper/Autogen ends'; - const VERSION_ID = 2018092102; + const VERSION_ID = 2018100101; protected $devHelperDirPath; diff --git a/PHPStan/Reflection/EntityRelationReflection.php b/PHPStan/Reflection/EntityRelationReflection.php index 79cf194..5639571 100644 --- a/PHPStan/Reflection/EntityRelationReflection.php +++ b/PHPStan/Reflection/EntityRelationReflection.php @@ -6,8 +6,10 @@ use PHPStan\Reflection\PropertyReflection; use PHPStan\Type\ArrayType; use PHPStan\Type\IntegerType; +use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use PHPStan\Type\UnionType; use XF\Mvc\Entity\Entity; class EntityRelationReflection implements PropertyReflection @@ -59,7 +61,7 @@ public function getType(): Type $className = str_replace(':', '\Entity\\', $this->entity); if ($this->type === Entity::TO_ONE) { - return new ObjectType($className); + return new UnionType([new NullType(), new ObjectType($className)]); } else { return new ArrayType(new IntegerType(), new ObjectType($className)); }