Skip to content

Commit 486992b

Browse files
committed
PHPStan fixes
1 parent 5ddaed5 commit 486992b

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

Diff for: phpstan.neon

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ parameters:
4444
path: src/Doctrine/Mapping/ClassMetadataFactory.php
4545
reportUnmatched: false
4646
-
47-
message: '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Connection and ''getNativeConnection'' will always evaluate to true\.$#'
47+
messages:
48+
- '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Connection and ''getNativeConnection'' will always evaluate to true\.$#'
49+
- '#^Cannot call method getWrappedResourceHandle\(\) on class\-string\|object\.$#'
4850
path: tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php
4951
reportUnmatched: false

Diff for: tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

+11-10
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;
@@ -28,10 +27,10 @@
2827
use function array_combine;
2928
use function array_keys;
3029
use function function_exists;
31-
use function get_class;
3230
use function get_debug_type;
3331
use function getenv;
3432
use function gettype;
33+
use function is_a;
3534
use function is_resource;
3635
use function method_exists;
3736
use function reset;
@@ -374,14 +373,14 @@ private function setupAttributes($nativeConnection, array $attributes): void
374373
}
375374
}
376375

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

382381
} elseif ($nativeConnection instanceof SQLite3) {
383382
if ($attributes !== []) {
384-
throw new LogicException('Cannot set attributes for ' . NativePgsqlConnection::class . ' driver');
383+
throw new LogicException('Cannot set attributes for ' . SQLite3::class . ' driver');
385384
}
386385

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

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

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

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

0 commit comments

Comments
 (0)