Skip to content

Commit 617b7e2

Browse files
committed
PHPStan fixes
1 parent 5ddaed5 commit 617b7e2

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use LogicException;
1515
use mysqli;
1616
use PDO;
17-
use PgSql\Connection as NativePgsqlConnection;
1817
use PHPStan\Platform\MatrixEntity\TestEntity;
1918
use PHPStan\Testing\PHPStanTestCase;
2019
use PHPStan\Type\ConstantTypeHelper;
@@ -32,6 +31,7 @@
3231
use function get_debug_type;
3332
use function getenv;
3433
use function gettype;
34+
use function is_a;
3535
use function is_resource;
3636
use function method_exists;
3737
use function reset;
@@ -374,14 +374,14 @@ private function setupAttributes($nativeConnection, array $attributes): void
374374
}
375375
}
376376

377-
} elseif ($nativeConnection instanceof NativePgsqlConnection) {
377+
} elseif (is_a($nativeConnection, 'PgSql\Connection', true)) {
378378
if ($attributes !== []) {
379-
throw new LogicException('Cannot set attributes for ' . NativePgsqlConnection::class . ' driver');
379+
throw new LogicException('Cannot set attributes for PgSql\Connection driver');
380380
}
381381

382382
} elseif ($nativeConnection instanceof SQLite3) {
383383
if ($attributes !== []) {
384-
throw new LogicException('Cannot set attributes for ' . NativePgsqlConnection::class . ' driver');
384+
throw new LogicException('Cannot set attributes for ' . SQLite3::class . ' driver');
385385
}
386386

387387
} elseif (is_resource($nativeConnection)) { // e.g. `resource (pgsql link)` on PHP < 8.1 with pgsql driver
@@ -403,12 +403,14 @@ private function getNativeConnection(Connection $connection)
403403
return $connection->getNativeConnection();
404404
}
405405

406-
if ($connection->getWrappedConnection() instanceof PDO) {
407-
return $connection->getWrappedConnection();
408-
}
406+
if (method_exists($connection, 'getWrappedConnection')) {
407+
if ($connection->getWrappedConnection() instanceof PDO) {
408+
return $connection->getWrappedConnection();
409+
}
409410

410-
if (get_class($connection->getWrappedConnection()) === 'Doctrine\DBAL\Driver\Mysqli\MysqliConnection' && method_exists($connection->getWrappedConnection(), 'getWrappedResourceHandle')) {
411-
return $connection->getWrappedConnection()->getWrappedResourceHandle();
411+
if (get_class($connection->getWrappedConnection()) === 'Doctrine\DBAL\Driver\Mysqli\MysqliConnection' && method_exists($connection->getWrappedConnection(), 'getWrappedResourceHandle')) {
412+
return $connection->getWrappedConnection()->getWrappedResourceHandle();
413+
}
412414
}
413415

414416
throw new LogicException('Unable to get native connection');

0 commit comments

Comments
 (0)