From ac2148898679fdfa8dbbcb27044158334a6c7ceb Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 9 Mar 2024 17:22:44 +0100 Subject: [PATCH] Try to work around Roave/infection-static-analysis-plugin#465 by changing trait override technique --- src/Connection.php | 1 + src/ConnectionTrait.php | 12 ++++++++++++ src/Connections/PrimaryReadReplicaConnection.php | 6 ++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index be3e275..7f0cff3 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -2,6 +2,7 @@ namespace Facile\DoctrineMySQLComeBack\Doctrine\DBAL; +/** @psalm-suppress PropertyNotSetInConstructor */ class Connection extends \Doctrine\DBAL\Connection { use ConnectionTrait; diff --git a/src/ConnectionTrait.php b/src/ConnectionTrait.php index 9691980..97f19bb 100644 --- a/src/ConnectionTrait.php +++ b/src/ConnectionTrait.php @@ -39,6 +39,18 @@ public function __construct( Driver $driver, ?Configuration $config = null ) { + $this->commonConstructor($params, $driver, $config); + } + + /** + * @param array $params + * @param Driver $driver + * @param Configuration|null $config + * + * @return void + */ + private function commonConstructor(array &$params, Driver $driver, ?Configuration $config): void + { if (isset($params['driverOptions']['x_reconnect_attempts'])) { $this->maxReconnectAttempts = $this->validateAttemptsOption($params['driverOptions']['x_reconnect_attempts']); unset($params['driverOptions']['x_reconnect_attempts']); diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index c6b64e5..5314479 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -8,9 +8,7 @@ class PrimaryReadReplicaConnection extends \Doctrine\DBAL\Connections\PrimaryReadReplicaConnection { - use ConnectionTrait { - __construct as __traitConstruct; - } + use ConnectionTrait; public function __construct(array $params, Driver $driver, ?Configuration $config = null) { @@ -19,6 +17,6 @@ public function __construct(array $params, Driver $driver, ?Configuration $confi unset($params['primary']['driverOptions']['x_reconnect_attempts']); } - self::__traitConstruct($params, $driver, $config); + $this->commonConstructor($params, $driver, $config); } }