Fix #2065 add ReturnTypeWillChange attribute to DBHelper

This commit is contained in:
Kijin Sung 2023-01-16 21:16:13 +09:00
parent b8351bf3c8
commit 8e2c4b3ef9
2 changed files with 15 additions and 15 deletions

View file

@ -31,10 +31,11 @@ class DBHelper extends \PDO
* Create a prepared statement. * Create a prepared statement.
* *
* @param string $statement * @param string $statement
* @param array $driver_options * @param array $options
* @return PDOStatement|DBStmtHelper * @return DBStmtHelper
*/ */
public function prepare($statement, $driver_options = null) #[\ReturnTypeWillChange]
public function prepare(string $statement, array $options = []): DBStmtHelper
{ {
$start_time = microtime(true); $start_time = microtime(true);
$db_class = DB::getInstance($this->_type); $db_class = DB::getInstance($this->_type);
@ -46,7 +47,7 @@ class DBHelper extends \PDO
* This allows it to track the parent database's type * This allows it to track the parent database's type
* and send query logs to the appropriate place. * and send query logs to the appropriate place.
*/ */
$stmt = $driver_options ? parent::prepare($statement, $driver_options) : parent::prepare($statement); $stmt = $options ? parent::prepare($statement, $options) : parent::prepare($statement);
$stmt->setFetchMode(\PDO::FETCH_OBJ); $stmt->setFetchMode(\PDO::FETCH_OBJ);
$stmt->setType($this->_type); $stmt->setType($this->_type);
$db_class->clearError(); $db_class->clearError();
@ -84,9 +85,11 @@ class DBHelper extends \PDO
* various kinds of additional parameters, and we don't want to touch them. * various kinds of additional parameters, and we don't want to touch them.
* *
* @param string $statement * @param string $statement
* @return PDOStatement|DBStmtHelper * @param int $fetch_mode
* @return DBStmtHelper
*/ */
public function query($statement, $fetch_mode = \PDO::FETCH_OBJ, ...$fetch_mode_args) #[\ReturnTypeWillChange]
public function query(string $statement, ?int $fetch_mode = \PDO::FETCH_OBJ, ...$fetch_mode_args): DBStmtHelper
{ {
$start_time = microtime(true); $start_time = microtime(true);
$db_class = DB::getInstance($this->_type); $db_class = DB::getInstance($this->_type);
@ -126,9 +129,10 @@ class DBHelper extends \PDO
* Execute a query and return the number of affected rows. * Execute a query and return the number of affected rows.
* *
* @param string $statement * @param string $statement
* @return bool * @return int|false
*/ */
public function exec($query) #[\ReturnTypeWillChange]
public function exec(string $query)
{ {
$start_time = microtime(true); $start_time = microtime(true);
$db_class = DB::getInstance($this->_type); $db_class = DB::getInstance($this->_type);

View file

@ -31,21 +31,17 @@ class DBStmtHelper extends \PDOStatement
/** /**
* Execute a prepared statement. * Execute a prepared statement.
* *
* We don't set a type for $input_parameters because the original * @param array $params
* PDOStatement class accepts both arrays and null. Actually, the null
* value must be omitted altogether or it will throw an error.
*
* @param array $input_parameters
* @return bool * @return bool
*/ */
public function execute($input_parameters = null): bool public function execute(?array $params = null): bool
{ {
$start_time = microtime(true); $start_time = microtime(true);
$db_class = DB::getInstance($this->_type); $db_class = DB::getInstance($this->_type);
try try
{ {
$result = parent::execute($input_parameters); $result = parent::execute($params);
$db_class->clearError(); $db_class->clearError();
} }
catch (\PDOException $e) catch (\PDOException $e)