Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor MysqliResultObjectType #634

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Extensions/MysqliQueryDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
38 changes: 36 additions & 2 deletions src/MysqliReflection/MysqliResultObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, Type> $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) {

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (reflection replay) (8.1, mysqli, replay)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, mysql:8.0, mysqli, recording)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (reflection replay) (8.1, pdo-mysql, replay)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, mariadb:latest, mysqli, recording)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, mysql:8.0, mysqli, recording)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, mariadb:latest, mysqli, recording)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, mysql:8.0, mysqli, recording)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, mariadb:latest, mysqli, recording)

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, mysql:8.0, pdo-mysql, recording, --health-cmd="mysqladmin ping" --health-interval=1...

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, mysql:8.0, pdo-mysql, recording, --health-cmd="mysqladmin ping" --health-interval=1...

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.

Check failure on line 25 in src/MysqliReflection/MysqliResultObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, mysql:8.0, mysqli, replay-and-recording, --health-cmd="mysqladmin ping" --health-in...

Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.
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);
}
}
Loading