diff --git a/src/Extensions/MysqliQueryDynamicReturnTypeExtension.php b/src/Extensions/MysqliQueryDynamicReturnTypeExtension.php index 39187960b..fad6e454c 100644 --- a/src/Extensions/MysqliQueryDynamicReturnTypeExtension.php +++ b/src/Extensions/MysqliQueryDynamicReturnTypeExtension.php @@ -129,7 +129,7 @@ private function inferResultType(Expr $queryExpr, Scope $scope): ?Type return null; } - $genericObjects[] = new MysqliResultObjectType($resultType); + $genericObjects[] = new MysqliResultObjectType([$resultType]); } if (0 === \count($genericObjects)) { diff --git a/src/MysqliReflection/MysqliResultObjectType.php b/src/MysqliReflection/MysqliResultObjectType.php index bac614a60..f37d1ddb5 100644 --- a/src/MysqliReflection/MysqliResultObjectType.php +++ b/src/MysqliReflection/MysqliResultObjectType.php @@ -5,13 +5,47 @@ namespace staabm\PHPStanDba\MysqliReflection; use mysqli_result; +use PHPStan\TrinaryLogic; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Type; final class MysqliResultObjectType extends GenericObjectType { - public function __construct(Type $rowType) + /** + * @param array $types + */ + public function __construct(array $types, ?Type $subtractedType = null) { - parent::__construct(mysqli_result::class, [$rowType]); + parent::__construct(mysqli_result::class, $types, $subtractedType); + } + + public function getTypeWithoutSubtractedType(): Type + { + $withoutSubtracted = $this->changeSubtractedType(null); + if ($withoutSubtracted instanceof GenericObjectType) { + return new self( + $withoutSubtracted->getTypes(), + $withoutSubtracted->getSubtractedType() + ); + } + return $withoutSubtracted; + } + + public function equals(Type $type): bool + { + if ($type instanceof self) { + return false; + } + + return parent::equals($type); + } + + public function isSuperTypeOf(Type $type): TrinaryLogic + { + if ($type instanceof self) { + return TrinaryLogic::createFromBoolean($this->equals($type)); + } + + return parent::isSuperTypeOf($type); } }