From ed19445f74c30854c60873cd1df1c38e15fc316b Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Fri, 7 Jan 2022 10:05:09 +0100 Subject: Optimise Minz_ModelPdo::class (#4119) * - Fix typo, - remove unnecessary null in property, - remove unused property, - add phpDoc, - add ext PDO in composer.json, - use strict comparison, - indentation * Translate * Update lib/Minz/ModelPdo.php Co-authored-by: Frans de Jonge * The code is more explicite * Fix phpstan * Fix phpstan expect one * Fix phpstan * Return in back... * make fix-all * Fix exception and more types * Fix more types * Remove ext- in composer.json Co-authored-by: Luc SANCHEZ Co-authored-by: Frans de Jonge Co-authored-by: Alexandre Alapetite --- lib/Minz/Pdo.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/Minz/Pdo.php') diff --git a/lib/Minz/Pdo.php b/lib/Minz/Pdo.php index 08436393e..9dcf0e5fa 100644 --- a/lib/Minz/Pdo.php +++ b/lib/Minz/Pdo.php @@ -6,7 +6,7 @@ */ abstract class Minz_Pdo extends PDO { - public function __construct($dsn, $username = null, $passwd = null, $options = null) { + public function __construct(string $dsn, $username = null, $passwd = null, $options = null) { parent::__construct($dsn, $username, $passwd, $options); $this->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } @@ -14,18 +14,18 @@ abstract class Minz_Pdo extends PDO { abstract public function dbType(); private $prefix = ''; - public function prefix() { + public function prefix(): string { return $this->prefix; } - public function setPrefix($prefix) { + public function setPrefix(string $prefix) { $this->prefix = $prefix; } - private function autoPrefix($sql) { + private function autoPrefix(string $sql): string { return str_replace('`_', '`' . $this->prefix, $sql); } - protected function preSql($statement) { + protected function preSql(string $statement): string { if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { invalidateHttpCache(); } @@ -43,14 +43,14 @@ abstract class Minz_Pdo extends PDO { // PHP8+: PDO::prepare(string $query, array $options = []): PDOStatement|false #[\ReturnTypeWillChange] - public function prepare($statement, $driver_options = array()) { + public function prepare(string $statement, array $driver_options = []) { $statement = $this->preSql($statement); return parent::prepare($statement, $driver_options); } // PHP8+: PDO::exec(string $statement): int|false #[\ReturnTypeWillChange] - public function exec($statement) { + public function exec(string $statement) { $statement = $this->preSql($statement); return parent::exec($statement); } -- cgit v1.2.3