From 8b9285f84b0640a9a3c6f80c5f2e8505d1e0b3ac Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Sun, 28 Jul 2024 05:40:01 +0200 Subject: [PATCH] Configure nullable types explicitly to avoid deprecation warnings in PHP 8.4 (#73) --- src/Codeception/Lib/DbPopulator.php | 2 +- src/Codeception/Lib/Driver/Db.php | 6 +++--- src/Codeception/Lib/Driver/Sqlite.php | 2 +- src/Codeception/Module/Db.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Codeception/Lib/DbPopulator.php b/src/Codeception/Lib/DbPopulator.php index 59d9b23b..22e3aa27 100644 --- a/src/Codeception/Lib/DbPopulator.php +++ b/src/Codeception/Lib/DbPopulator.php @@ -53,7 +53,7 @@ public function __construct(array $config) * @param string|null $dumpFile The dump file to build the command with. * @return string The resulting command string after evaluating any configuration's key */ - protected function buildCommand(string $command, string $dumpFile = null): string + protected function buildCommand(string $command, ?string $dumpFile = null): string { $dsn = $this->config['dsn'] ?? ''; $dsnVars = []; diff --git a/src/Codeception/Lib/Driver/Db.php b/src/Codeception/Lib/Driver/Db.php index 519b6790..e8041ecf 100755 --- a/src/Codeception/Lib/Driver/Db.php +++ b/src/Codeception/Lib/Driver/Db.php @@ -31,7 +31,7 @@ class Db */ protected array $primaryKeys = []; - public static function connect(string $dsn, string $user = null, string $password = null, array $options = null): PDO + public static function connect(string $dsn, ?string $user = null, ?string $password = null, ?array $options = null): PDO { $dbh = new PDO($dsn, $user, $password, $options); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -47,7 +47,7 @@ public static function connect(string $dsn, string $user = null, string $passwor * * @return Db|SqlSrv|MySql|Oci|PostgreSql|Sqlite */ - public static function create(string $dsn, string $user = null, string $password = null, array $options = null): Db + public static function create(string $dsn, ?string $user = null, ?string $password = null, ?array $options = null): Db { $provider = self::getProvider($dsn); @@ -78,7 +78,7 @@ public static function getProvider($dsn): string * @see https://www.php.net/manual/en/pdo.construct.php * @see https://www.php.net/manual/de/ref.pdo-mysql.php#pdo-mysql.constants */ - public function __construct(string $dsn, string $user = null, string $password = null, array $options = null) + public function __construct(string $dsn, ?string $user = null, ?string $password = null, ?array $options = null) { $this->dbh = new PDO($dsn, $user, $password, $options); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); diff --git a/src/Codeception/Lib/Driver/Sqlite.php b/src/Codeception/Lib/Driver/Sqlite.php index f480c76d..e539649d 100644 --- a/src/Codeception/Lib/Driver/Sqlite.php +++ b/src/Codeception/Lib/Driver/Sqlite.php @@ -14,7 +14,7 @@ class Sqlite extends Db protected string $filename = ''; - public function __construct(string $dsn, string $user = null, string $password = null, array $options = null) + public function __construct(string $dsn, ?string $user = null, ?string $password = null, ?array $options = null) { $filename = substr($dsn, 7); if ($filename === ':memory:') { diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 699e5d3b..b78eb721 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -684,7 +684,7 @@ protected function removeInserted($databaseKey = null): void $this->insertedRows[$databaseKey] = []; } - public function _cleanup(string $databaseKey = null, array $databaseConfig = null): void + public function _cleanup(?string $databaseKey = null, ?array $databaseConfig = null): void { $databaseKey = empty($databaseKey) ? self::DEFAULT_DATABASE : $databaseKey; $databaseConfig = empty($databaseConfig) ? $this->config : $databaseConfig; @@ -737,7 +737,7 @@ public function _isPopulated() return $this->databasesPopulated[$this->currentDatabase]; } - public function _loadDump(string $databaseKey = null, array $databaseConfig = null): void + public function _loadDump(?string $databaseKey = null, ?array $databaseConfig = null): void { $databaseKey = empty($databaseKey) ? self::DEFAULT_DATABASE : $databaseKey; $databaseConfig = empty($databaseConfig) ? $this->config : $databaseConfig;