14
14
use LogicException ;
15
15
use mysqli ;
16
16
use PDO ;
17
- use PgSql \Connection as NativePgsqlConnection ;
18
17
use PHPStan \Platform \MatrixEntity \TestEntity ;
19
18
use PHPStan \Testing \PHPStanTestCase ;
20
19
use PHPStan \Type \ConstantTypeHelper ;
32
31
use function get_debug_type ;
33
32
use function getenv ;
34
33
use function gettype ;
34
+ use function is_a ;
35
35
use function is_resource ;
36
36
use function method_exists ;
37
37
use function reset ;
@@ -374,14 +374,14 @@ private function setupAttributes($nativeConnection, array $attributes): void
374
374
}
375
375
}
376
376
377
- } elseif ($ nativeConnection instanceof NativePgsqlConnection ) {
377
+ } elseif (is_a ( $ nativeConnection, ' PgSql\Connection ' , true ) ) {
378
378
if ($ attributes !== []) {
379
- throw new LogicException ('Cannot set attributes for ' . NativePgsqlConnection::class . ' driver ' );
379
+ throw new LogicException ('Cannot set attributes for PgSql\Connection driver ' );
380
380
}
381
381
382
382
} elseif ($ nativeConnection instanceof SQLite3) {
383
383
if ($ attributes !== []) {
384
- throw new LogicException ('Cannot set attributes for ' . NativePgsqlConnection ::class . ' driver ' );
384
+ throw new LogicException ('Cannot set attributes for ' . SQLite3 ::class . ' driver ' );
385
385
}
386
386
387
387
} 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)
403
403
return $ connection ->getNativeConnection ();
404
404
}
405
405
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
+ }
409
410
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
+ }
412
414
}
413
415
414
416
throw new LogicException ('Unable to get native connection ' );
0 commit comments