From 2754f95d99f995ea9f8e6b27d3f670e133ee465d Mon Sep 17 00:00:00 2001 From: Werner Spiegel Date: Sun, 17 Oct 2021 12:48:22 +0200 Subject: [PATCH 01/23] allow psr/log v2 (#191) * allow psr/log v2 widens the restriction for which logger interface to use. similar to how symfony handles this: https://github.com/symfony/console/blob/5.3/composer.json#L34 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 60a08354..5813ab87 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ], "require": { "php": ">=5.6.0", - "psr/log": "^1.0" + "psr/log": "^1.0 || ^2.0" }, "autoload": { "psr-4": { From 8600f897437d959084766c12c5e0a3e04b560d80 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 28 Oct 2021 09:47:17 +0100 Subject: [PATCH 02/23] php 8.1 support --- src/PdoInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index 23754c0a..e8c9b359 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -28,7 +28,7 @@ interface PdoInterface * @see http://php.net/manual/en/pdo.begintransaction.php * */ - public function beginTransaction(); + public function beginTransaction(): bool; /** * From 1ea6b17001d27cc2de5457f6a39fbdbcbed61bc5 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 28 Oct 2021 12:44:05 +0100 Subject: [PATCH 03/23] php 8.1 support --- composer.json | 3 +- src/AbstractExtendedPdo.php | 151 +++++++++++++++-------------- src/ConnectionLocator.php | 35 ++++--- src/ConnectionLocatorInterface.php | 21 ++-- src/DecoratedPdo.php | 18 ++-- src/ExtendedPdo.php | 37 ++++--- src/ExtendedPdoInterface.php | 74 +++++++------- src/Parser/AbstractParser.php | 30 +++--- src/Parser/MysqlParser.php | 4 +- src/Parser/NullParser.php | 8 +- src/Parser/ParserInterface.php | 2 +- src/Parser/PgsqlParser.php | 4 +- src/PdoInterface.php | 49 +++++----- src/Profiler/MemoryLogger.php | 9 +- src/Profiler/Profiler.php | 54 +++++------ src/Profiler/ProfilerInterface.php | 32 +++--- tests/ConnectionLocatorTest.php | 2 +- tests/ExtendedPdoTest.php | 20 ++-- tests/Parser/MysqlParserTest.php | 2 +- tests/Parser/PgsqlParserTest.php | 2 +- tests/Parser/SqliteParserTest.php | 2 +- tests/Profiler/ProfilerTest.php | 2 +- 22 files changed, 273 insertions(+), 288 deletions(-) diff --git a/composer.json b/composer.json index 8d8cfa7f..987c8101 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ ], "require": { "php": ">=5.6.0", - "psr/log": "^1.0" + "psr/log": "^1.0", + "ext-pdo": "*" }, "autoload": { "psr-4": { diff --git a/src/AbstractExtendedPdo.php b/src/AbstractExtendedPdo.php index 483740bb..84d4dc2f 100644 --- a/src/AbstractExtendedPdo.php +++ b/src/AbstractExtendedPdo.php @@ -8,10 +8,10 @@ */ namespace Aura\Sql; -use Aura\Sql\Exception; use Aura\Sql\Parser\ParserInterface; use Aura\Sql\Profiler\ProfilerInterface; use BadMethodCallException; +use Generator; use PDO; use PDOStatement; @@ -32,7 +32,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @var PDO * */ - protected $pdo; + protected ?PDO $pdo = null; /** * @@ -41,7 +41,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @var ProfilerInterface * */ - protected $profiler; + protected ProfilerInterface $profiler; /** * @@ -50,7 +50,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @var ParserInterface * */ - protected $parser; + protected ParserInterface $parser; /** * @@ -59,7 +59,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @var string * */ - protected $quoteNamePrefix = '"'; + protected string $quoteNamePrefix = '"'; /** * @@ -68,7 +68,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @var string * */ - protected $quoteNameSuffix = '"'; + protected string $quoteNameSuffix = '"'; /** * @@ -77,7 +77,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @var string * */ - protected $quoteNameEscapeFind = '"'; + protected string $quoteNameEscapeFind = '"'; /** * @@ -86,7 +86,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @var string * */ - protected $quoteNameEscapeRepl = '""'; + protected string $quoteNameEscapeRepl = '""'; /** * @@ -103,13 +103,13 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * @throws BadMethodCallException when the method does not exist. * */ - public function __call($name, array $arguments) + public function __call(string $name, array $arguments) { $this->connect(); if (! method_exists($this->pdo, $name)) { $class = get_class($this); - $message = "Class '{$class}' does not have a method '{$name}'"; + $message = "Class '$class' does not have a method '$name'"; throw new BadMethodCallException($message); } @@ -125,7 +125,7 @@ public function __call($name, array $arguments) * @see http://php.net/manual/en/pdo.begintransaction.php * */ - public function beginTransaction() + public function beginTransaction(): bool { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -143,7 +143,7 @@ public function beginTransaction() * @see http://php.net/manual/en/pdo.commit.php * */ - public function commit() + public function commit(): bool { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -156,28 +156,26 @@ public function commit() * * Connects to the database. * - * @return null - * + * @return void */ - abstract public function connect(); + abstract public function connect(): void; /** * * Disconnects from the database. * - * @return null - * + * @return void */ - abstract public function disconnect(); + abstract public function disconnect(): void; /** * * Gets the most recent error code. * - * @return mixed + * @return string|null * */ - public function errorCode() + public function errorCode(): ?string { $this->connect(); return $this->pdo->errorCode(); @@ -190,7 +188,7 @@ public function errorCode() * @return array * */ - public function errorInfo() + public function errorInfo(): array { $this->connect(); return $this->pdo->errorInfo(); @@ -207,7 +205,7 @@ public function errorInfo() * @see http://php.net/manual/en/pdo.exec.php * */ - public function exec($statement) + public function exec(string $statement): int { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -227,7 +225,7 @@ public function exec($statement) * @return int * */ - public function fetchAffected($statement, array $values = []) + public function fetchAffected(string $statement, array $values = []): int { $sth = $this->perform($statement, $values); return $sth->rowCount(); @@ -245,7 +243,7 @@ public function fetchAffected($statement, array $values = []) * @return array * */ - public function fetchAll($statement, array $values = []) + public function fetchAll(string $statement, array $values = []): array { $sth = $this->perform($statement, $values); return $sth->fetchAll(self::FETCH_ASSOC); @@ -267,7 +265,7 @@ public function fetchAll($statement, array $values = []) * @return array * */ - public function fetchAssoc($statement, array $values = []) + public function fetchAssoc(string $statement, array $values = []): array { $sth = $this->perform($statement, $values); $data = []; @@ -288,7 +286,7 @@ public function fetchAssoc($statement, array $values = []) * @return array * */ - public function fetchCol($statement, array $values = []) + public function fetchCol(string $statement, array $values = []): array { $sth = $this->perform($statement, $values); return $sth->fetchAll(self::FETCH_COLUMN, 0); @@ -310,10 +308,10 @@ public function fetchCol($statement, array $values = []) * */ public function fetchGroup( - $statement, + string $statement, array $values = [], - $style = PDO::FETCH_COLUMN - ) { + int $style = PDO::FETCH_COLUMN + ): array { $sth = $this->perform($statement, $values); return $sth->fetchAll(self::FETCH_GROUP | $style); } @@ -342,11 +340,11 @@ public function fetchGroup( * */ public function fetchObject( - $statement, + string $statement, array $values = [], - $class = 'stdClass', + string $class = 'stdClass', array $args = [] - ) { + ): object { $sth = $this->perform($statement, $values); if (! empty($args)) { @@ -382,11 +380,11 @@ public function fetchObject( * */ public function fetchObjects( - $statement, + string $statement, array $values = [], - $class = 'stdClass', + string $class = 'stdClass', array $args = [] - ) { + ): array { $sth = $this->perform($statement, $values); if (! empty($args)) { @@ -404,10 +402,10 @@ public function fetchObjects( * * @param array $values Values to bind to the query. * - * @return array + * @return array|false * */ - public function fetchOne($statement, array $values = []) + public function fetchOne(string $statement, array $values = []): array|false { $sth = $this->perform($statement, $values); return $sth->fetch(self::FETCH_ASSOC); @@ -425,7 +423,7 @@ public function fetchOne($statement, array $values = []) * @return array * */ - public function fetchPairs($statement, array $values = []) + public function fetchPairs(string $statement, array $values = []): array { $sth = $this->perform($statement, $values); return $sth->fetchAll(self::FETCH_KEY_PAIR); @@ -442,7 +440,7 @@ public function fetchPairs($statement, array $values = []) * @return mixed * */ - public function fetchValue($statement, array $values = []) + public function fetchValue(string $statement, array $values = []): mixed { $sth = $this->perform($statement, $values); return $sth->fetchColumn(0); @@ -455,7 +453,7 @@ public function fetchValue($statement, array $values = []) * @return ParserInterface * */ - public function getParser() + public function getParser(): ParserInterface { return $this->parser; } @@ -467,7 +465,7 @@ public function getParser() * @return \PDO * */ - public function getPdo() + public function getPdo(): PDO { return $this->pdo; } @@ -479,7 +477,7 @@ public function getPdo() * @return ProfilerInterface * */ - public function getProfiler() + public function getProfiler(): ProfilerInterface { return $this->profiler; } @@ -493,7 +491,7 @@ public function getProfiler() * @see http://php.net/manual/en/pdo.intransaction.php * */ - public function inTransaction() + public function inTransaction(): bool { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -509,7 +507,7 @@ public function inTransaction() * @return bool * */ - public function isConnected() + public function isConnected(): bool { return (bool) $this->pdo; } @@ -518,15 +516,14 @@ public function isConnected() * * Returns the last inserted autoincrement sequence value. * - * @param string $name The name of the sequence to check; typically needed + * @param string|null $name The name of the sequence to check; typically needed * only for PostgreSQL, where it takes the form of `__seq`. * - * @return string + * @return string|false * * @see http://php.net/manual/en/pdo.lastinsertid.php - * */ - public function lastInsertId($name = null) + public function lastInsertId(?string $name = null): string|false { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -547,10 +544,11 @@ public function lastInsertId($name = null) * * @return PDOStatement * + * @throws \Aura\Sql\Exception\CannotBindValue * @see quote() * */ - public function perform($statement, array $values = []) + public function perform(string $statement, array $values = []): PDOStatement { $this->connect(); $sth = $this->prepareWithValues($statement, $values); @@ -574,7 +572,7 @@ public function perform($statement, array $values = []) * @see http://php.net/manual/en/pdo.prepare.php * */ - public function prepare($statement, $options = []) + public function prepare(string $statement, array $options = []): PDOStatement { $this->connect(); $sth = $this->pdo->prepare($statement, $options); @@ -600,10 +598,11 @@ public function prepare($statement, $options = []) * * @return PDOStatement * + * @throws \Aura\Sql\Exception\CannotBindValue * @see http://php.net/manual/en/pdo.prepare.php * */ - public function prepareWithValues($statement, array $values = []) + public function prepareWithValues(string $statement, array $values = []): PDOStatement { // if there are no values to bind ... if (empty($values)) { @@ -615,7 +614,7 @@ public function prepareWithValues($statement, array $values = []) // rebuild the statement and values $parser = clone $this->parser; - list ($statement, $values) = $parser->rebuild($statement, $values); + list($statement, $values) = $parser->rebuild($statement, $values); // prepare the statement $sth = $this->pdo->prepare($statement); @@ -635,18 +634,20 @@ public function prepareWithValues($statement, array $values = []) * * @param string $statement The SQL statement to prepare and execute. * - * @param mixed ...$fetch Optional fetch-related parameters. + * @param int|null $fetchMode + * + * @param mixed ...$fetch_mode_args Optional fetch-related parameters. * * @return PDOStatement * * @see http://php.net/manual/en/pdo.query.php * */ - public function query($statement, ...$fetch) + public function query($statement, $fetchMode = null, mixed ...$fetch_mode_args): PDOStatement { $this->connect(); $this->profiler->start(__FUNCTION__); - $sth = $this->pdo->query($statement, ...$fetch); + $sth = $this->pdo->query($statement, $fetchMode, ...$fetch_mode_args); $this->profiler->finish($sth->queryString); return $sth; } @@ -667,7 +668,7 @@ public function query($statement, ...$fetch) * @see http://php.net/manual/en/pdo.quote.php * */ - public function quote($value, $type = self::PARAM_STR) + public function quote(mixed $value, int $type = self::PARAM_STR): string { $this->connect(); @@ -692,7 +693,7 @@ public function quote($value, $type = self::PARAM_STR) * @return string The multi-part identifier name, quoted. * */ - public function quoteName($name) + public function quoteName(string $name): string { if (strpos($name, '.') === false) { return $this->quoteSingleName($name); @@ -716,7 +717,7 @@ public function quoteName($name) * @return string The quoted identifier name. * */ - public function quoteSingleName($name) + public function quoteSingleName(string $name): string { $name = str_replace( $this->quoteNameEscapeFind, @@ -737,7 +738,7 @@ public function quoteSingleName($name) * @see http://php.net/manual/en/pdo.rollback.php * */ - public function rollBack() + public function rollBack(): bool { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -753,7 +754,7 @@ public function rollBack() * @param ParserInterface $parser The Parser instance. * */ - public function setParser(ParserInterface $parser) + public function setParser(ParserInterface $parser): void { $this->parser = $parser; } @@ -765,7 +766,7 @@ public function setParser(ParserInterface $parser) * @param ProfilerInterface $profiler The Profiler instance. * */ - public function setProfiler(ProfilerInterface $profiler) + public function setProfiler(ProfilerInterface $profiler): void { $this->profiler = $profiler; } @@ -781,7 +782,7 @@ public function setProfiler(ProfilerInterface $profiler) * @return \Generator * */ - public function yieldAll($statement, array $values = []) + public function yieldAll(string $statement, array $values = []): Generator { $sth = $this->perform($statement, $values); while ($row = $sth->fetch(self::FETCH_ASSOC)) { @@ -800,7 +801,7 @@ public function yieldAll($statement, array $values = []) * @return \Generator * */ - public function yieldAssoc($statement, array $values = []) + public function yieldAssoc(string $statement, array $values = []): Generator { $sth = $this->perform($statement, $values); while ($row = $sth->fetch(self::FETCH_ASSOC)) { @@ -820,7 +821,7 @@ public function yieldAssoc($statement, array $values = []) * @return \Generator * */ - public function yieldCol($statement, array $values = []) + public function yieldCol(string $statement, array $values = []): Generator { $sth = $this->perform($statement, $values); while ($row = $sth->fetch(self::FETCH_NUM)) { @@ -851,11 +852,11 @@ public function yieldCol($statement, array $values = []) * */ public function yieldObjects( - $statement, + string $statement, array $values = [], - $class = 'stdClass', + string $class = 'stdClass', array $args = [] - ) { + ): Generator { $sth = $this->perform($statement, $values); if (empty($args)) { @@ -881,7 +882,7 @@ public function yieldObjects( * @return \Generator * */ - public function yieldPairs($statement, array $values = []) + public function yieldPairs(string $statement, array $values = []): Generator { $sth = $this->perform($statement, $values); while ($row = $sth->fetch(self::FETCH_NUM)) { @@ -899,13 +900,13 @@ public function yieldPairs($statement, array $values = []) * * @param mixed $val The value to bind to the statement. * - * @return boolean + * @return bool * * @throws Exception\CannotBindValue when the value to be bound is not * bindable (e.g., array, object, or resource). * */ - protected function bindValue(PDOStatement $sth, $key, $val) + protected function bindValue(PDOStatement $sth, mixed $key, mixed $val): bool { if (is_int($val)) { return $sth->bindValue($key, $val, self::PARAM_INT); @@ -938,7 +939,7 @@ protected function bindValue(PDOStatement $sth, $key, $val) * @return ParserInterface * */ - protected function newParser($driver) + protected function newParser(string $driver): ParserInterface { $class = 'Aura\Sql\Parser\\' . ucfirst($driver) . 'Parser'; if (! class_exists($class)) { @@ -953,10 +954,10 @@ protected function newParser($driver) * * @param string $driver The PDO driver name. * - * @return null + * @return void * */ - protected function setQuoteName($driver) + protected function setQuoteName(string $driver): void { switch ($driver) { case 'mysql': @@ -987,7 +988,7 @@ protected function setQuoteName($driver) * @param int $attribute * @return mixed */ - public function getAttribute($attribute) + public function getAttribute(int $attribute): mixed { $this->connect(); return $this->pdo->getAttribute($attribute); @@ -1001,7 +1002,7 @@ public function getAttribute($attribute) * @param mixed $value * @return bool */ - public function setAttribute($attribute, $value) + public function setAttribute(int $attribute, mixed$value): bool { $this->connect(); return $this->pdo->setAttribute($attribute, $value); diff --git a/src/ConnectionLocator.php b/src/ConnectionLocator.php index 80a8fbe0..90a78369 100644 --- a/src/ConnectionLocator.php +++ b/src/ConnectionLocator.php @@ -33,7 +33,7 @@ class ConnectionLocator implements ConnectionLocatorInterface * @var array * */ - protected $read = []; + protected array $read = []; /** * @@ -42,13 +42,13 @@ class ConnectionLocator implements ConnectionLocatorInterface * @var array * */ - protected $write = []; + protected array $write = []; /** * * Constructor. * - * @param callable $default A callable to create a default connection. + * @param callable|null $default A callable to create a default connection. * * @param array $read An array of callables to create read connections. * @@ -56,7 +56,7 @@ class ConnectionLocator implements ConnectionLocatorInterface * */ public function __construct( - $default = null, + ?callable $default = null, array $read = [], array $write = [] ) { @@ -77,10 +77,9 @@ public function __construct( * * @param callable $callable The factory for the connection. * - * @return null - * + * @return void */ - public function setDefault(callable $callable) + public function setDefault(callable $callable): void { $this->default = $callable; } @@ -92,7 +91,7 @@ public function setDefault(callable $callable) * @return ExtendedPdoInterface * */ - public function getDefault() + public function getDefault(): ExtendedPdoInterface { if (! $this->default instanceof ExtendedPdo) { $this->default = call_user_func($this->default); @@ -109,10 +108,9 @@ public function getDefault() * * @param callable $callable The factory for the connection. * - * @return null - * + * @return void */ - public function setRead($name, callable $callable) + public function setRead(string $name, callable $callable): void { $this->read[$name] = $callable; } @@ -127,8 +125,9 @@ public function setRead($name, callable $callable) * * @return ExtendedPdoInterface * + * @throws \Aura\Sql\Exception\ConnectionNotFound */ - public function getRead($name = '') + public function getRead(string $name = ''): ExtendedPdoInterface { return $this->getConnection('read', $name); } @@ -141,10 +140,9 @@ public function getRead($name = '') * * @param callable $callable The factory for the connection. * - * @return null - * + * @return void */ - public function setWrite($name, callable $callable) + public function setWrite(string $name, callable $callable): void { $this->write[$name] = $callable; } @@ -159,8 +157,9 @@ public function setWrite($name, callable $callable) * * @return ExtendedPdoInterface * + * @throws \Aura\Sql\Exception\ConnectionNotFound */ - public function getWrite($name = '') + public function getWrite(string $name = ''): ExtendedPdoInterface { return $this->getConnection('write', $name); } @@ -178,7 +177,7 @@ public function getWrite($name = '') * @throws Exception\ConnectionNotFound * */ - protected function getConnection($type, $name) + protected function getConnection(string $type, string $name): ExtendedPdoInterface { $conn = &$this->{$type}; @@ -191,7 +190,7 @@ protected function getConnection($type, $name) } if (! isset($conn[$name])) { - throw new Exception\ConnectionNotFound("{$type}:{$name}"); + throw new Exception\ConnectionNotFound("$type:$name"); } if (! $conn[$name] instanceof ExtendedPdo) { diff --git a/src/ConnectionLocatorInterface.php b/src/ConnectionLocatorInterface.php index 5daf99c2..e30beb6f 100644 --- a/src/ConnectionLocatorInterface.php +++ b/src/ConnectionLocatorInterface.php @@ -23,10 +23,9 @@ interface ConnectionLocatorInterface * * @param callable $callable The registry entry. * - * @return null - * + * @return void */ - public function setDefault(callable $callable); + public function setDefault(callable $callable): void; /** * @@ -35,7 +34,7 @@ public function setDefault(callable $callable); * @return ExtendedPdoInterface * */ - public function getDefault(); + public function getDefault(): ExtendedPdoInterface; /** * @@ -45,10 +44,9 @@ public function getDefault(); * * @param callable $callable The registry entry. * - * @return null - * + * @return void */ - public function setRead($name, callable $callable); + public function setRead(string $name, callable $callable): void; /** * @@ -61,7 +59,7 @@ public function setRead($name, callable $callable); * @return ExtendedPdoInterface * */ - public function getRead($name = ''); + public function getRead(string $name = ''): ExtendedPdoInterface; /** * @@ -71,10 +69,9 @@ public function getRead($name = ''); * * @param callable $callable The registry entry. * - * @return null - * + * @return void */ - public function setWrite($name, callable $callable); + public function setWrite(string $name, callable $callable): void; /** * @@ -87,5 +84,5 @@ public function setWrite($name, callable $callable); * @return ExtendedPdoInterface * */ - public function getWrite($name = ''); + public function getWrite(string $name = ''): ExtendedPdoInterface; } diff --git a/src/DecoratedPdo.php b/src/DecoratedPdo.php index 8916b86a..8438b46a 100644 --- a/src/DecoratedPdo.php +++ b/src/DecoratedPdo.php @@ -30,17 +30,14 @@ class DecoratedPdo extends AbstractExtendedPdo * * @param PDO $pdo An existing PDO instance to decorate. * - * @param ProfilerInterface $profiler Tracks and logs query profiles. + * @param ProfilerInterface|null $profiler Tracks and logs query profiles. * */ - public function __construct(PDO $pdo, ProfilerInterface $profiler = null) + public function __construct(PDO $pdo, ?ProfilerInterface $profiler = null) { $this->pdo = $pdo; - if ($profiler === null) { - $profiler = new Profiler(); - } - $this->setProfiler($profiler); + $this->setProfiler($profiler ?? new Profiler()); $driver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); $this->setParser($this->newParser($driver)); @@ -51,10 +48,10 @@ public function __construct(PDO $pdo, ProfilerInterface $profiler = null) * * Connects to the database. * - * @return null + * @return void * */ - public function connect() + public function connect(): void { // already connected } @@ -63,10 +60,11 @@ public function connect() * * Disconnects from the database; disallowed with decorated PDO connections. * - * @return null + * @return void * + * @throws Exception\CannotDisconnect */ - public function disconnect() + public function disconnect(): void { $message = "Cannot disconnect a DecoratedPdo instance."; throw new Exception\CannotDisconnect($message); diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 18820e68..6916e011 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -10,6 +10,7 @@ use Aura\Sql\Profiler\Profiler; use Aura\Sql\Profiler\ProfilerInterface; +use JetBrains\PhpStorm\ArrayShape; use PDO; /** @@ -28,7 +29,7 @@ class ExtendedPdo extends AbstractExtendedPdo * @var array * */ - protected $args = []; + protected array $args = []; /** * @@ -39,26 +40,25 @@ class ExtendedPdo extends AbstractExtendedPdo * * @param string $dsn The data source name for the connection. * - * @param string $username The username for the connection. + * @param string|null $username The username for the connection. * - * @param string $password The password for the connection. + * @param string|null $password The password for the connection. * * @param array $options Driver-specific options for the connection. * * @param array $queries Queries to execute after the connection. * - * @param ProfilerInterface $profiler Tracks and logs query profiles. + * @param \Aura\Sql\Profiler\ProfilerInterface|null $profiler Tracks and logs query profiles. * * @see http://php.net/manual/en/pdo.construct.php - * */ public function __construct( - $dsn, - $username = null, - $password = null, + string $dsn, + ?string $username = null, + ?string $password = null, array $options = [], array $queries = [], - ProfilerInterface $profiler = null + ?ProfilerInterface $profiler = null ) { // if no error mode is specified, use exceptions if (! isset($options[PDO::ATTR_ERRMODE])) { @@ -75,10 +75,7 @@ public function __construct( ]; // retain a profiler, instantiating a default one if needed - if ($profiler === null) { - $profiler = new Profiler(); - } - $this->setProfiler($profiler); + $this->setProfiler($profiler ?? new Profiler()); // retain a query parser $parts = explode(':', $dsn); @@ -93,10 +90,9 @@ public function __construct( * * Connects to the database. * - * @return null - * + * @return void */ - public function connect() + public function connect(): void { if ($this->pdo) { return; @@ -118,10 +114,10 @@ public function connect() * * Disconnects from the database. * - * @return null + * @return void * */ - public function disconnect() + public function disconnect(): void { $this->profiler->start(__FUNCTION__); $this->pdo = null; @@ -135,7 +131,8 @@ public function disconnect() * @return array * */ - public function __debugInfo() + #[ArrayShape(['args' => "array"])] + public function __debugInfo(): array { return [ 'args' => [ @@ -155,7 +152,7 @@ public function __debugInfo() * @return \PDO * */ - public function getPdo() + public function getPdo(): PDO { $this->connect(); return $this->pdo; diff --git a/src/ExtendedPdoInterface.php b/src/ExtendedPdoInterface.php index 323c3f65..e82ae94a 100644 --- a/src/ExtendedPdoInterface.php +++ b/src/ExtendedPdoInterface.php @@ -10,7 +10,9 @@ use Aura\Sql\Parser\ParserInterface; use Aura\Sql\Profiler\ProfilerInterface; +use Generator; use PDO; +use PDOStatement; /** * @@ -26,14 +28,14 @@ interface ExtendedPdoInterface extends PdoInterface * Connects to the database. * */ - public function connect(); + public function connect(): void; /** * * Disconnects from the database. * */ - public function disconnect(); + public function disconnect(): void; /** * @@ -46,7 +48,7 @@ public function disconnect(); * @return int * */ - public function fetchAffected($statement, array $values = []); + public function fetchAffected(string $statement, array $values = []): int; /** * @@ -60,7 +62,7 @@ public function fetchAffected($statement, array $values = []); * @return array * */ - public function fetchAll($statement, array $values = []); + public function fetchAll(string $statement, array $values = []): array; /** * @@ -78,7 +80,7 @@ public function fetchAll($statement, array $values = []); * @return array * */ - public function fetchAssoc($statement, array $values = []); + public function fetchAssoc(string $statement, array $values = []): array; /** * @@ -91,7 +93,7 @@ public function fetchAssoc($statement, array $values = []); * @return array * */ - public function fetchCol($statement, array $values = []); + public function fetchCol(string $statement, array $values = []): array; /** * @@ -109,10 +111,10 @@ public function fetchCol($statement, array $values = []); * */ public function fetchGroup( - $statement, + string $statement, array $values = [], - $style = PDO::FETCH_COLUMN - ); + int $style = PDO::FETCH_COLUMN + ): array; /** * @@ -137,11 +139,11 @@ public function fetchGroup( * */ public function fetchObject( - $statement, + string $statement, array $values = [], - $class = 'stdClass', + string $class = 'stdClass', array $args = [] - ); + ): object; /** * @@ -168,11 +170,11 @@ public function fetchObject( * */ public function fetchObjects( - $statement, + string $statement, array $values = [], - $class = 'stdClass', + string $class = 'stdClass', array $args = [] - ); + ): array; /** * @@ -182,10 +184,10 @@ public function fetchObjects( * * @param array $values Values to bind to the query. * - * @return array + * @return array|false * */ - public function fetchOne($statement, array $values = []); + public function fetchOne(string $statement, array $values = []): array|false; /** * @@ -199,7 +201,7 @@ public function fetchOne($statement, array $values = []); * @return array * */ - public function fetchPairs($statement, array $values = []); + public function fetchPairs(string $statement, array $values = []): array; /** * @@ -212,7 +214,7 @@ public function fetchPairs($statement, array $values = []); * @return mixed * */ - public function fetchValue($statement, array $values = []); + public function fetchValue(string $statement, array $values = []): mixed; /** * @@ -221,7 +223,7 @@ public function fetchValue($statement, array $values = []); * @return ParserInterface * */ - public function getParser(); + public function getParser(): ParserInterface; /** * @@ -230,7 +232,7 @@ public function getParser(); * @return \PDO * */ - public function getPdo(); + public function getPdo(): PDO; /** * @@ -239,7 +241,7 @@ public function getPdo(); * @return ProfilerInterface * */ - public function getProfiler(); + public function getProfiler(): ProfilerInterface; /** * @@ -250,7 +252,7 @@ public function getProfiler(); * @return string The multi-part identifier name, quoted. * */ - public function quoteName($name); + public function quoteName(string $name): string; /** * @@ -261,7 +263,7 @@ public function quoteName($name); * @return string The quoted identifier name. * */ - public function quoteSingleName($name); + public function quoteSingleName(string $name): string; /** * @@ -270,7 +272,7 @@ public function quoteSingleName($name); * @return bool * */ - public function isConnected(); + public function isConnected(): bool; /** * @@ -279,7 +281,7 @@ public function isConnected(); * @param ParserInterface $parser The Parser instance. * */ - public function setParser(ParserInterface $parser); + public function setParser(ParserInterface $parser): void; /** * @@ -288,7 +290,7 @@ public function setParser(ParserInterface $parser); * @param ProfilerInterface $profiler The Profiler instance. * */ - public function setProfiler(ProfilerInterface $profiler); + public function setProfiler(ProfilerInterface $profiler): void; /** * @@ -301,7 +303,7 @@ public function setProfiler(ProfilerInterface $profiler); * @return \Generator * */ - public function yieldAll($statement, array $values = []); + public function yieldAll(string $statement, array $values = []): Generator; /** * @@ -314,7 +316,7 @@ public function yieldAll($statement, array $values = []); * @return \Generator * */ - public function yieldAssoc($statement, array $values = []); + public function yieldAssoc(string $statement, array $values = []): Generator; /** * @@ -327,7 +329,7 @@ public function yieldAssoc($statement, array $values = []); * @return \Generator * */ - public function yieldCol($statement, array $values = []); + public function yieldCol(string $statement, array $values = []): Generator; /** * @@ -352,11 +354,11 @@ public function yieldCol($statement, array $values = []); * */ public function yieldObjects( - $statement, + string $statement, array $values = [], - $class = 'stdClass', + string $class = 'stdClass', array $args = [] - ); + ): Generator; /** * @@ -370,7 +372,7 @@ public function yieldObjects( * @return \Generator * */ - public function yieldPairs($statement, array $values = []); + public function yieldPairs(string $statement, array $values = []): Generator; /** * @@ -384,7 +386,7 @@ public function yieldPairs($statement, array $values = []); * @return \PDOStatement * */ - public function perform($statement, array $values = []); + public function perform(string $statement, array $values = []): PDOStatement; /** * @@ -408,5 +410,5 @@ public function perform($statement, array $values = []); * @see http://php.net/manual/en/pdo.prepare.php * */ - public function prepareWithValues($statement, array $values = []); + public function prepareWithValues(string $statement, array $values = []): PDOStatement; } diff --git a/src/Parser/AbstractParser.php b/src/Parser/AbstractParser.php index 4405dfff..007244de 100644 --- a/src/Parser/AbstractParser.php +++ b/src/Parser/AbstractParser.php @@ -29,7 +29,7 @@ abstract class AbstractParser implements ParserInterface * @var array * */ - protected $split = [ + protected array $split = [ // single-quoted string "'(?:[^'\\\\]|\\\\'?)*'", // double-quoted string @@ -43,7 +43,7 @@ abstract class AbstractParser implements ParserInterface * @var string * */ - protected $skip = '/^(\'|\"|\:[^a-zA-Z_])/um'; + protected string $skip = '/^(\'|\"|\:[^a-zA-Z_])/um'; /** * @@ -52,7 +52,7 @@ abstract class AbstractParser implements ParserInterface * @var int * */ - protected $num = 0; + protected int $num = 0; /** * @@ -61,7 +61,7 @@ abstract class AbstractParser implements ParserInterface * @var array * */ - protected $count = [ + protected array $count = [ '__' => null, ]; @@ -72,7 +72,7 @@ abstract class AbstractParser implements ParserInterface * @var array * */ - protected $values = []; + protected array $values = []; /** * @@ -81,7 +81,7 @@ abstract class AbstractParser implements ParserInterface * @var array * */ - protected $final_values = []; + protected array $final_values = []; /** * @@ -95,7 +95,7 @@ abstract class AbstractParser implements ParserInterface * element 1 is the rebuilt array of values. * */ - public function rebuild($statement, array $values = []) + public function rebuild(string $statement, array $values = []): array { // match standard PDO execute() behavior of zero-indexed arrays if (array_key_exists(0, $values)) { @@ -116,7 +116,7 @@ public function rebuild($statement, array $values = []) * @return string The rebuilt statement. * */ - protected function rebuildStatement($statement) + protected function rebuildStatement(string $statement): string { $parts = $this->getParts($statement); return $this->rebuildParts($parts); @@ -131,7 +131,7 @@ protected function rebuildStatement($statement) * @return string The rebuilt statement. * */ - protected function rebuildParts(array $parts) + protected function rebuildParts(array $parts): string { $statement = ''; foreach ($parts as $part) { @@ -149,7 +149,7 @@ protected function rebuildParts(array $parts) * @return string The rebuilt statement. * */ - protected function rebuildPart($part) + protected function rebuildPart(string $part): string { if (preg_match($this->skip, $part)) { return $part; @@ -176,7 +176,7 @@ protected function rebuildPart($part) * @return string The prepared subparts. * */ - protected function prepareValuePlaceholders(array $subs) + protected function prepareValuePlaceholders(array $subs): string { $str = ''; foreach ($subs as $i => $sub) { @@ -230,7 +230,7 @@ protected function prepareNumberedPlaceholder() * @return string The prepared query subpart. * */ - protected function prepareNamedPlaceholder($sub) + protected function prepareNamedPlaceholder(string $sub): string { $orig = substr($sub, 1); if (array_key_exists($orig, $this->values) === false) { @@ -260,7 +260,7 @@ protected function prepareNamedPlaceholder($sub) * @return string * */ - protected function getPlaceholderName($orig) + protected function getPlaceholderName(string $orig): string { if (! isset($this->count[$orig])) { $this->count[$orig] = 0; @@ -283,7 +283,7 @@ protected function getPlaceholderName($orig) * @return string * */ - protected function expandNamedPlaceholder($prefix, array $values) + protected function expandNamedPlaceholder(string $prefix, array $values): string { $i = 0; $expanded = []; @@ -305,7 +305,7 @@ protected function expandNamedPlaceholder($prefix, array $values) * @return array * */ - protected function getParts($statement) + protected function getParts(string $statement): array { $split = implode('|', $this->split); return preg_split( diff --git a/src/Parser/MysqlParser.php b/src/Parser/MysqlParser.php index f516f551..7066abac 100644 --- a/src/Parser/MysqlParser.php +++ b/src/Parser/MysqlParser.php @@ -24,7 +24,7 @@ class MysqlParser extends AbstractParser * @var array * */ - protected $split = [ + protected array $split = [ // single-quoted string "'(?:[^'\\\\]|\\\\'?)*'", // double-quoted string @@ -40,5 +40,5 @@ class MysqlParser extends AbstractParser * @var string * */ - protected $skip = '/^(\'|\"|\`)/um'; + protected string $skip = '/^(\'|\"|\`)/um'; } diff --git a/src/Parser/NullParser.php b/src/Parser/NullParser.php index 09af509a..a6534a39 100644 --- a/src/Parser/NullParser.php +++ b/src/Parser/NullParser.php @@ -22,15 +22,15 @@ class NullParser implements ParserInterface * * Leaves the query and parameters alone. * - * @param string $statement The query statement string. + * @param string $string The query statement string. * - * @param array $values Bind these values into the query. + * @param array $parameters Bind these values into the query. * * @return array * */ - public function rebuild($statement, array $values = []) + public function rebuild(string $string, array $parameters = []): array { - return [$statement, $values]; + return [$string, $parameters]; } } diff --git a/src/Parser/ParserInterface.php b/src/Parser/ParserInterface.php index dc138079..b90dd922 100644 --- a/src/Parser/ParserInterface.php +++ b/src/Parser/ParserInterface.php @@ -30,5 +30,5 @@ interface ParserInterface * element 1 is the rebuilt array of values. * */ - public function rebuild($string, array $parameters = []); + public function rebuild(string $string, array $parameters = []): array; } diff --git a/src/Parser/PgsqlParser.php b/src/Parser/PgsqlParser.php index ead10f73..261cf5da 100644 --- a/src/Parser/PgsqlParser.php +++ b/src/Parser/PgsqlParser.php @@ -24,7 +24,7 @@ class PgsqlParser extends AbstractParser * @var array * */ - protected $split = [ + protected array $split = [ // single-quoted string "'(?:[^'\\\\]|\\\\'?)*'", // double-quoted string @@ -42,5 +42,5 @@ class PgsqlParser extends AbstractParser * @var string * */ - protected $skip = '/^(\'|\"|\$|\:[^a-zA-Z_])/um'; + protected string $skip = '/^(\'|\"|\$|\:[^a-zA-Z_])/um'; } diff --git a/src/PdoInterface.php b/src/PdoInterface.php index e8c9b359..cf7191c5 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -9,6 +9,7 @@ namespace Aura\Sql; use PDO; +use PDOStatement; /** * @@ -39,16 +40,15 @@ public function beginTransaction(): bool; * @see http://php.net/manual/en/pdo.commit.php * */ - public function commit(); + public function commit(): bool; /** * * Gets the most recent error code. * - * @return mixed - * + * @return string|null */ - public function errorCode(); + public function errorCode(): ?string; /** * @@ -57,7 +57,7 @@ public function errorCode(); * @return array * */ - public function errorInfo(); + public function errorInfo(): array; /** * @@ -70,18 +70,18 @@ public function errorInfo(); * @see http://php.net/manual/en/pdo.exec.php * */ - public function exec($statement); + public function exec(string $statement): int; /** * * Gets a PDO attribute value. * - * @param mixed $attribute The PDO::ATTR_* constant. + * @param int $attribute The PDO::ATTR_* constant. * * @return mixed The value for the attribute. * */ - public function getAttribute($attribute); + public function getAttribute(int $attribute): mixed; /** * @@ -92,21 +92,21 @@ public function getAttribute($attribute); * @see http://php.net/manual/en/pdo.intransaction.php * */ - public function inTransaction(); + public function inTransaction(): bool; /** * * Returns the last inserted autoincrement sequence value. * - * @param string $name The name of the sequence to check; typically needed + * @param string|null $name The name of the sequence to check; typically needed * only for PostgreSQL, where it takes the form of `
__seq`. * - * @return string + * @return string|false * * @see http://php.net/manual/en/pdo.lastinsertid.php * */ - public function lastInsertId($name = null); + public function lastInsertId(?string $name = null): string|false; /** * @@ -117,12 +117,11 @@ public function lastInsertId($name = null); * @param array $options Set these attributes on the returned * PDOStatement. * - * @return \PDOStatement + * @return \PDOStatement|false * * @see http://php.net/manual/en/pdo.prepare.php - * */ - public function prepare($statement, $options = null); + public function prepare(string $statement, array $options = []): PDOStatement|false; /** * @@ -130,14 +129,16 @@ public function prepare($statement, $options = null); * * @param string $statement The SQL statement to prepare and execute. * - * @param mixed ...$fetch Optional fetch-related parameters. + * @param int|null $fetchMode + * + * @param mixed ...$fetch_mode_args Optional fetch-related parameters. * - * @return \PDOStatement + * @return \PDOStatement|false * * @see http://php.net/manual/en/pdo.query.php * */ - public function query($statement, ...$fetch); + public function query($statement, $fetchMode = null, ...$fetch_mode_args): PDOStatement|false; /** * @@ -147,12 +148,12 @@ public function query($statement, ...$fetch); * * @param int $parameter_type A data type hint for the database driver. * - * @return string The quoted value. + * @return string|false The quoted value. * * @see http://php.net/manual/en/pdo.quote.php * */ - public function quote($value, $parameter_type = PDO::PARAM_STR); + public function quote(mixed $value, int $parameter_type = PDO::PARAM_STR): string|false; /** * @@ -163,20 +164,20 @@ public function quote($value, $parameter_type = PDO::PARAM_STR); * @see http://php.net/manual/en/pdo.rollback.php * */ - public function rollBack(); + public function rollBack(): bool; /** * * Sets a PDO attribute value. * - * @param mixed $attribute The PDO::ATTR_* constant. + * @param int $attribute The PDO::ATTR_* constant. * * @param mixed $value The value for the attribute. * * @return bool * */ - public function setAttribute($attribute, $value); + public function setAttribute(int $attribute, mixed $value): bool; /** * @@ -185,5 +186,5 @@ public function setAttribute($attribute, $value); * @return array * */ - public static function getAvailableDrivers(); + //public static function getAvailableDrivers(): array; } diff --git a/src/Profiler/MemoryLogger.php b/src/Profiler/MemoryLogger.php index c94e564f..78184eed 100644 --- a/src/Profiler/MemoryLogger.php +++ b/src/Profiler/MemoryLogger.php @@ -26,7 +26,7 @@ class MemoryLogger extends AbstractLogger * @var array * */ - protected $messages = []; + protected array $messages = []; /** * @@ -38,10 +38,9 @@ class MemoryLogger extends AbstractLogger * * @param array $context Data to interpolate into the message. * - * @return null - * + * @return void */ - public function log($level, $message, array $context = []) + public function log($level, $message, array $context = []): void { $replace = []; foreach ($context as $key => $val) { @@ -57,7 +56,7 @@ public function log($level, $message, array $context = []) * @return array * */ - public function getMessages() + public function getMessages(): array { return $this->messages; } diff --git a/src/Profiler/Profiler.php b/src/Profiler/Profiler.php index 6f341bc8..42d591b6 100644 --- a/src/Profiler/Profiler.php +++ b/src/Profiler/Profiler.php @@ -28,7 +28,7 @@ class Profiler implements ProfilerInterface * @var array * */ - protected $context = []; + protected array $context = []; /** * @@ -37,7 +37,7 @@ class Profiler implements ProfilerInterface * @var LoggerInterface * */ - protected $logger; + protected LoggerInterface $logger; /** * @@ -48,7 +48,7 @@ class Profiler implements ProfilerInterface * @see setActive() * */ - protected $active = false; + protected bool $active = false; /** * @@ -59,7 +59,7 @@ class Profiler implements ProfilerInterface * @see setLogLevel() * */ - protected $logLevel = LogLevel::DEBUG; + protected string $logLevel = LogLevel::DEBUG; /** * @@ -70,21 +70,17 @@ class Profiler implements ProfilerInterface * @see setLogFormat() * */ - protected $logFormat = "{function} ({duration} seconds): {statement} {backtrace}"; + protected string $logFormat = "{function} ({duration} seconds): {statement} {backtrace}"; /** * * Constructor. * - * @param LoggerInterface $logger Record profiles through this interface. - * + * @param \Psr\Log\LoggerInterface|null $logger Record profiles through this interface. */ - public function __construct(LoggerInterface $logger = null) + public function __construct(?LoggerInterface $logger = null) { - if ($logger === null) { - $logger = new MemoryLogger(); - } - $this->logger = $logger; + $this->logger = $logger ?? new MemoryLogger(); } /** @@ -94,9 +90,9 @@ public function __construct(LoggerInterface $logger = null) * @param bool $active * */ - public function setActive($active) + public function setActive(bool $active) { - $this->active = (bool) $active; + $this->active = $active; } /** @@ -106,7 +102,7 @@ public function setActive($active) * @return bool * */ - public function isActive() + public function isActive(): bool { return $this->active; } @@ -118,7 +114,7 @@ public function isActive() * @return \Psr\Log\LoggerInterface * */ - public function getLogger() + public function getLogger(): LoggerInterface { return $this->logger; } @@ -130,7 +126,7 @@ public function getLogger() * @return string * */ - public function getLogLevel() + public function getLogLevel(): string { return $this->logLevel; } @@ -141,10 +137,9 @@ public function getLogLevel() * * @param string $logLevel A PSR LogLevel constant. * - * @return null - * + * @return void */ - public function setLogLevel($logLevel) + public function setLogLevel(string $logLevel): void { $this->logLevel = $logLevel; } @@ -156,7 +151,7 @@ public function setLogLevel($logLevel) * @return string * */ - public function getLogFormat() + public function getLogFormat(): string { return $this->logFormat; } @@ -167,10 +162,9 @@ public function getLogFormat() * * @param string $logFormat * - * @return null - * + * @return void */ - public function setLogFormat($logFormat) + public function setLogFormat(string $logFormat): void { $this->logFormat = $logFormat; } @@ -181,10 +175,9 @@ public function setLogFormat($logFormat) * * @param string $function The function starting the profile entry. * - * @return null - * + * @return void */ - public function start($function) + public function start(string $function): void { if (! $this->active) { return; @@ -200,14 +193,13 @@ public function start($function) * * Finishes and logs a profile entry. * - * @param string $statement The statement being profiled, if any. + * @param string|null $statement The statement being profiled, if any. * * @param array $values The values bound to the statement, if any. * - * @return null - * + * @return void */ - public function finish($statement = null, array $values = []) + public function finish(?string $statement = null, array $values = []): void { if (! $this->active) { return; diff --git a/src/Profiler/ProfilerInterface.php b/src/Profiler/ProfilerInterface.php index 14d114b4..ae1f6a89 100644 --- a/src/Profiler/ProfilerInterface.php +++ b/src/Profiler/ProfilerInterface.php @@ -24,7 +24,7 @@ interface ProfilerInterface * @param bool $active * */ - public function setActive($active); + public function setActive(bool $active); /** * @@ -33,7 +33,7 @@ public function setActive($active); * @return bool * */ - public function isActive(); + public function isActive(): bool; /** * @@ -42,7 +42,7 @@ public function isActive(); * @return \Psr\Log\LoggerInterface * */ - public function getLogger(); + public function getLogger(): \Psr\Log\LoggerInterface; /** * @@ -51,7 +51,7 @@ public function getLogger(); * @return string * */ - public function getLogLevel(); + public function getLogLevel(): string; /** * @@ -59,10 +59,9 @@ public function getLogLevel(); * * @param string $logLevel A PSR LogLevel constant. * - * @return null - * + * @return void */ - public function setLogLevel($logLevel); + public function setLogLevel(string $logLevel): void; /** * @@ -71,7 +70,7 @@ public function setLogLevel($logLevel); * @return string * */ - public function getLogFormat(); + public function getLogFormat(): string; /** * @@ -79,10 +78,9 @@ public function getLogFormat(); * * @param string $logFormat * - * @return null - * + * @return void */ - public function setLogFormat($logFormat); + public function setLogFormat(string $logFormat): void; /** * @@ -90,21 +88,19 @@ public function setLogFormat($logFormat); * * @param string $function The function starting the profile entry. * - * @return null - * + * @return void */ - public function start($function); + public function start(string $function): void; /** * * Finishes and logs a profile entry. * - * @param string $statement The statement being profiled, if any. + * @param string|null $statement The statement being profiled, if any. * * @param array $values The values bound to the statement, if any. * - * @return null - * + * @return void */ - public function finish($statement = null, array $values = []); + public function finish(?string $statement = null, array $values = []): void; } diff --git a/tests/ConnectionLocatorTest.php b/tests/ConnectionLocatorTest.php index 46c76ec5..146729fd 100644 --- a/tests/ConnectionLocatorTest.php +++ b/tests/ConnectionLocatorTest.php @@ -18,7 +18,7 @@ class ConnectionLocatorTest extends TestCase protected $write = []; - protected function setUp() + protected function setUp(): void { $this->conns = [ 'default' => new ExtendedPdo('sqlite::memory:'), diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index 7e300902..c51a9a6e 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -23,7 +23,7 @@ class ExtendedPdoTest extends TestCase 10 => 'Kara', ]; - public function setUp() + public function setUp(): void { if (! extension_loaded('pdo_sqlite')) { $this->markTestSkipped("Need 'pdo_sqlite' to test in memory."); @@ -79,7 +79,7 @@ public function testCall() } $this->pdo->sqliteCreateFunction('foo', function () {}); - $this->setExpectedException('BadMethodCallException'); + $this->expectException('BadMethodCallException'); $this->pdo->sqliteNoSuchMethod(); } @@ -106,6 +106,8 @@ public function testConnectionQueries() // make sure new encoding was honored $actual = $pdo->fetchValue('PRAGMA encoding'); + + $this->assertStringStartsWith('UTF-16', $actual); } public function testErrorCodeAndInfo() @@ -296,7 +298,7 @@ public function testFetchObject() { $stm = "SELECT id, name FROM pdotest WHERE id = ?"; $actual = $this->pdo->fetchObject($stm, [1]); - $this->assertSame('1', $actual->id); + $this->assertSame(1, $actual->id); $this->assertSame('Anna', $actual->name); } @@ -309,7 +311,7 @@ public function testFetchObject_withCtorArgs() 'Aura\Sql\FakeObject', ['bar'] ); - $this->assertSame('1', $actual->id); + $this->assertSame(1, $actual->id); $this->assertSame('Anna', $actual->name); $this->assertSame('bar', $actual->foo); } @@ -653,15 +655,15 @@ public function testNoExportOfLoginCredentials() $data = $this->dump($pdo); // DSN - $this->assertContains('[0]=>string(15) "sqlite::memory:"', $data); + $this->assertStringContainsString('[0]=>string(15) "sqlite::memory:"', $data); // username - $this->assertContains('[1]=>string(4) "****"', $data); + $this->assertStringContainsString('[1]=>string(4) "****"', $data); // password - $this->assertContains('[2]=>string(4) "****"', $data); + $this->assertStringContainsString('[2]=>string(4) "****"', $data); // options - $this->assertContains('[3]=>array(1) {[3]=>int(2)}', $data); + $this->assertStringContainsString('[3]=>array(1) {[3]=>int(2)}', $data); // queries - $this->assertContains('[4]=>array(0) {}', $data); + $this->assertStringContainsString('[4]=>array(0) {}', $data); } protected function dump($pdo) diff --git a/tests/Parser/MysqlParserTest.php b/tests/Parser/MysqlParserTest.php index 305e63ae..0a85baf0 100644 --- a/tests/Parser/MysqlParserTest.php +++ b/tests/Parser/MysqlParserTest.php @@ -3,7 +3,7 @@ class MysqlParserTest extends AbstractParserTest { - protected function setUp() + protected function setUp(): void { $this->parser = new MysqlParser(); } diff --git a/tests/Parser/PgsqlParserTest.php b/tests/Parser/PgsqlParserTest.php index 4a50dd58..b3cd4408 100644 --- a/tests/Parser/PgsqlParserTest.php +++ b/tests/Parser/PgsqlParserTest.php @@ -3,7 +3,7 @@ class PgsqlParserTest extends AbstractParserTest { - protected function setUp() + protected function setUp(): void { $this->parser = new PgsqlParser(); } diff --git a/tests/Parser/SqliteParserTest.php b/tests/Parser/SqliteParserTest.php index 8364ee06..44b2c435 100644 --- a/tests/Parser/SqliteParserTest.php +++ b/tests/Parser/SqliteParserTest.php @@ -3,7 +3,7 @@ class SqliteParserTest extends AbstractParserTest { - protected function setUp() + protected function setUp(): void { $this->parser = new SqliteParser(); } diff --git a/tests/Profiler/ProfilerTest.php b/tests/Profiler/ProfilerTest.php index b143ad22..e523052a 100644 --- a/tests/Profiler/ProfilerTest.php +++ b/tests/Profiler/ProfilerTest.php @@ -6,7 +6,7 @@ class ProfilerTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->profiler = new Profiler(); } From 36696246e95f1c147ca0d8faa36539707158b577 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 28 Oct 2021 14:13:06 +0100 Subject: [PATCH 04/23] php 8.1 support --- .github/workflows/tests.yml | 2 +- tests/ExtendedPdoTest.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 315da067..a0178732 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + php-versions: ['8.0', '8.1'] steps: - name: Download standard files uses: actions/checkout@v2 diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index c51a9a6e..2398467b 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -193,7 +193,6 @@ public function testQueryWithFetchMode() ]; } $this->assertEquals($expect, $actual); - } public function testPrepareWithValues() @@ -298,7 +297,9 @@ public function testFetchObject() { $stm = "SELECT id, name FROM pdotest WHERE id = ?"; $actual = $this->pdo->fetchObject($stm, [1]); - $this->assertSame(1, $actual->id); + + // in php <= 8 id is a string, in php >= 8.1 it is a int + $this->assertSame('1', (string)$actual->id); $this->assertSame('Anna', $actual->name); } @@ -311,7 +312,8 @@ public function testFetchObject_withCtorArgs() 'Aura\Sql\FakeObject', ['bar'] ); - $this->assertSame(1, $actual->id); + // in php <= 8 id is a string, in php >= 8.1 it is a int + $this->assertSame('1', (string)$actual->id); $this->assertSame('Anna', $actual->name); $this->assertSame('bar', $actual->foo); } From 98614632fb6052a24f349a5342823ced0abea0e6 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 28 Oct 2021 14:38:14 +0100 Subject: [PATCH 05/23] php 8.1 support --- src/AbstractExtendedPdo.php | 2 ++ tests/ExtendedPdoTest.php | 1 + 2 files changed, 3 insertions(+) diff --git a/src/AbstractExtendedPdo.php b/src/AbstractExtendedPdo.php index 84d4dc2f..56b923de 100644 --- a/src/AbstractExtendedPdo.php +++ b/src/AbstractExtendedPdo.php @@ -672,6 +672,8 @@ public function quote(mixed $value, int $type = self::PARAM_STR): string { $this->connect(); + $value = $value ?? ''; + // non-array quoting if (! is_array($value)) { return $this->pdo->quote($value, $type); diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index 2398467b..ec3221ed 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -670,6 +670,7 @@ public function testNoExportOfLoginCredentials() protected function dump($pdo) { + ini_set('xdebug.cli_color', 0); ob_start(); var_dump($pdo); $data = ob_get_clean(); From 7050fa0bd034062d8f33ca3dda581bcb1b959273 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 28 Oct 2021 23:10:08 +0100 Subject: [PATCH 06/23] Remove JetBrains\PhpStorm\ArrayShape usage --- src/ExtendedPdo.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 6916e011..16e28194 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -10,7 +10,6 @@ use Aura\Sql\Profiler\Profiler; use Aura\Sql\Profiler\ProfilerInterface; -use JetBrains\PhpStorm\ArrayShape; use PDO; /** @@ -131,7 +130,6 @@ public function disconnect(): void * @return array * */ - #[ArrayShape(['args' => "array"])] public function __debugInfo(): array { return [ From b2989f9b6e19fb8330f34152cf42ec0d8396e3a4 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 28 Oct 2021 23:15:38 +0100 Subject: [PATCH 07/23] Fixing regression in composer.json with phpunit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8bca5259..c330a105 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "require-dev": { "pds/skeleton": "~1.0", - "phpunit/phpunit": "~5.0" + "phpunit/phpunit": "~5.7|~9.5" }, "autoload-dev": { "psr-4": { From 7fccf1b239fdac8507496ff7f389840272164824 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Wed, 3 Nov 2021 09:43:17 +0000 Subject: [PATCH 08/23] correctly set minimum php version in composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c330a105..f8fabb48 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "php": ">=5.6.0", + "php": ">=8.0", "psr/log": "^1.0 || ^2.0", "ext-pdo": "*" }, From 579e65311e5759098f5f8cd05703b9690eb62406 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Wed, 3 Nov 2021 10:10:18 +0000 Subject: [PATCH 09/23] Update composer.json to php 8.1 Co-authored-by: kenjis --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f8fabb48..fb5d5d74 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "php": ">=8.0", + "php": ">=8.1", "psr/log": "^1.0 || ^2.0", "ext-pdo": "*" }, From 4eb418b1cc439c1f1577d35301905a30d8f7b6b5 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Wed, 3 Nov 2021 10:13:57 +0000 Subject: [PATCH 10/23] Update .github/workflows/tests.yml to only test on with php 8.1 Co-authored-by: kenjis --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a0178732..6cb735e4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['8.0', '8.1'] + php-versions: ['8.1'] steps: - name: Download standard files uses: actions/checkout@v2 From 2eb448593307c6946be7c46a588e6a9b03412da1 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Wed, 3 Nov 2021 14:41:26 +0000 Subject: [PATCH 11/23] Update test for a change in behavior By default PDO now uses native types for int/floats instead of everything being strings. --- tests/ExtendedPdoTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index ec3221ed..68b331bb 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -299,7 +299,8 @@ public function testFetchObject() $actual = $this->pdo->fetchObject($stm, [1]); // in php <= 8 id is a string, in php >= 8.1 it is a int - $this->assertSame('1', (string)$actual->id); + // https://github.com/php/php-src/blob/PHP-8.1/UPGRADING#L131 + $this->assertSame(1, $actual->id); $this->assertSame('Anna', $actual->name); } @@ -313,7 +314,8 @@ public function testFetchObject_withCtorArgs() ['bar'] ); // in php <= 8 id is a string, in php >= 8.1 it is a int - $this->assertSame('1', (string)$actual->id); + // https://github.com/php/php-src/blob/PHP-8.1/UPGRADING#L131 + $this->assertSame(1, $actual->id); $this->assertSame('Anna', $actual->name); $this->assertSame('bar', $actual->foo); } From 04b6657c1d9f8c2d142c68c122cfa9aed8152cad Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 4 Nov 2021 08:50:52 +0000 Subject: [PATCH 12/23] correct docblock to match type --- src/AbstractExtendedPdo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractExtendedPdo.php b/src/AbstractExtendedPdo.php index 56b923de..51b84ded 100644 --- a/src/AbstractExtendedPdo.php +++ b/src/AbstractExtendedPdo.php @@ -29,7 +29,7 @@ abstract class AbstractExtendedPdo extends PDO implements ExtendedPdoInterface * * The internal PDO connection. * - * @var PDO + * @var PDO|null * */ protected ?PDO $pdo = null; From 42146a0871e4806b78f2a0f19b4cee7b7d67b2aa Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 4 Nov 2021 09:06:51 +0000 Subject: [PATCH 13/23] test null default connection within ConnectionLocator and throw ConnectionNotFound from getDefault() on a null default --- src/ConnectionLocator.php | 5 +++++ tests/ConnectionLocatorTest.php | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/ConnectionLocator.php b/src/ConnectionLocator.php index 90a78369..66cb1fa6 100644 --- a/src/ConnectionLocator.php +++ b/src/ConnectionLocator.php @@ -90,9 +90,14 @@ public function setDefault(callable $callable): void * * @return ExtendedPdoInterface * + * @throws Exception\ConnectionNotFound */ public function getDefault(): ExtendedPdoInterface { + if (! $this->default) { + throw new Exception\ConnectionNotFound("default"); + } + if (! $this->default instanceof ExtendedPdo) { $this->default = call_user_func($this->default); } diff --git a/tests/ConnectionLocatorTest.php b/tests/ConnectionLocatorTest.php index 146729fd..4d01daee 100644 --- a/tests/ConnectionLocatorTest.php +++ b/tests/ConnectionLocatorTest.php @@ -49,6 +49,13 @@ protected function newLocator($read = [], $write = []) return new ConnectionLocator($this->default, $read, $write); } + public function testNullDefault() + { + $locator = new ConnectionLocator(null, $this->read, $this->write); + $this->expectException('Aura\Sql\Exception\ConnectionNotFound'); + $locator->getDefault(); + } + public function testGetDefault() { $locator = $this->newLocator(); From 9d66473ac482c19345b5181ac91460673dc33773 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:02:43 +0000 Subject: [PATCH 14/23] Update src/PdoInterface.php Co-authored-by: kenjis --- src/PdoInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index cf7191c5..508084c6 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -70,7 +70,7 @@ public function errorInfo(): array; * @see http://php.net/manual/en/pdo.exec.php * */ - public function exec(string $statement): int; + public function exec(string $statement): int|false; /** * From 421633faba0b889747e7cd928dbac0cebf8bc4f6 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:03:55 +0000 Subject: [PATCH 15/23] Update src/PdoInterface.php Co-authored-by: kenjis --- src/PdoInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index 508084c6..a0325d54 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -121,7 +121,7 @@ public function lastInsertId(?string $name = null): string|false; * * @see http://php.net/manual/en/pdo.prepare.php */ - public function prepare(string $statement, array $options = []): PDOStatement|false; + public function prepare(string $query, array $options = []): PDOStatement|false; /** * From 4b84240402620474d5762cc81cc88ef2d662a50b Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:05:40 +0000 Subject: [PATCH 16/23] Update src/PdoInterface.php Co-authored-by: kenjis --- src/PdoInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index a0325d54..68c65352 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -127,7 +127,7 @@ public function prepare(string $query, array $options = []): PDOStatement|false; * * Queries the database and returns a PDOStatement. * - * @param string $statement The SQL statement to prepare and execute. + * @param string $query The SQL statement to prepare and execute. * * @param int|null $fetchMode * From 8de43afb07a8efd703f86f802f85159658400b11 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:06:03 +0000 Subject: [PATCH 17/23] Update src/PdoInterface.php Co-authored-by: kenjis --- src/PdoInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index 68c65352..3b227cd0 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -138,7 +138,7 @@ public function prepare(string $query, array $options = []): PDOStatement|false; * @see http://php.net/manual/en/pdo.query.php * */ - public function query($statement, $fetchMode = null, ...$fetch_mode_args): PDOStatement|false; + public function query(string $query, ?int $fetchMode = null, ...$fetch_mode_args): PDOStatement|false; /** * From 48914ec4c28d4fc9d2a408e4316782ebdbd70c7b Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:10:53 +0000 Subject: [PATCH 18/23] Update src/PdoInterface.php Co-authored-by: kenjis --- src/PdoInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index 3b227cd0..bffb457e 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -153,7 +153,7 @@ public function query(string $query, ?int $fetchMode = null, ...$fetch_mode_args * @see http://php.net/manual/en/pdo.quote.php * */ - public function quote(mixed $value, int $parameter_type = PDO::PARAM_STR): string|false; + public function quote(string|int|array|float|null $value, int $type = PDO::PARAM_STR): string|false; /** * From 52b534060716c4de7c1d38c8d1a655217eeb71b6 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:11:11 +0000 Subject: [PATCH 19/23] Update src/PdoInterface.php Co-authored-by: kenjis --- src/PdoInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index bffb457e..fbd6357e 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -81,7 +81,7 @@ public function exec(string $statement): int|false; * @return mixed The value for the attribute. * */ - public function getAttribute(int $attribute): mixed; + public function getAttribute(int $attribute): bool|int|string|array|null; /** * From aa574c96766e07aeafeff26c79caaa5bc51464a5 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:11:45 +0000 Subject: [PATCH 20/23] Update src/AbstractExtendedPdo.php Co-authored-by: kenjis --- src/AbstractExtendedPdo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractExtendedPdo.php b/src/AbstractExtendedPdo.php index 51b84ded..df4b4ae7 100644 --- a/src/AbstractExtendedPdo.php +++ b/src/AbstractExtendedPdo.php @@ -572,7 +572,7 @@ public function perform(string $statement, array $values = []): PDOStatement * @see http://php.net/manual/en/pdo.prepare.php * */ - public function prepare(string $statement, array $options = []): PDOStatement + public function prepare(string $query, array $options = []): PDOStatement { $this->connect(); $sth = $this->pdo->prepare($statement, $options); From 77746c246a437ee91087d61a6c27b539c650cc29 Mon Sep 17 00:00:00 2001 From: Steven Lewis Date: Sun, 7 Nov 2021 09:14:16 +0000 Subject: [PATCH 21/23] Apply suggestions from code review Co-authored-by: kenjis --- src/AbstractExtendedPdo.php | 12 ++++++------ src/PdoInterface.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AbstractExtendedPdo.php b/src/AbstractExtendedPdo.php index df4b4ae7..974bc83b 100644 --- a/src/AbstractExtendedPdo.php +++ b/src/AbstractExtendedPdo.php @@ -575,7 +575,7 @@ public function perform(string $statement, array $values = []): PDOStatement public function prepare(string $query, array $options = []): PDOStatement { $this->connect(); - $sth = $this->pdo->prepare($statement, $options); + $sth = $this->pdo->prepare($query, $options); return $sth; } @@ -643,11 +643,11 @@ public function prepareWithValues(string $statement, array $values = []): PDOSta * @see http://php.net/manual/en/pdo.query.php * */ - public function query($statement, $fetchMode = null, mixed ...$fetch_mode_args): PDOStatement + public function query(string $query, ?int $fetchMode = null, mixed ...$fetch_mode_args): PDOStatement { $this->connect(); $this->profiler->start(__FUNCTION__); - $sth = $this->pdo->query($statement, $fetchMode, ...$fetch_mode_args); + $sth = $this->pdo->query($query, $fetchMode, ...$fetch_mode_args); $this->profiler->finish($sth->queryString); return $sth; } @@ -668,7 +668,7 @@ public function query($statement, $fetchMode = null, mixed ...$fetch_mode_args): * @see http://php.net/manual/en/pdo.quote.php * */ - public function quote(mixed $value, int $type = self::PARAM_STR): string + public function quote(string|int|array|float|null $value, int $type = self::PARAM_STR): string { $this->connect(); @@ -990,7 +990,7 @@ protected function setQuoteName(string $driver): void * @param int $attribute * @return mixed */ - public function getAttribute(int $attribute): mixed + public function getAttribute(int $attribute): bool|int|string|array|null { $this->connect(); return $this->pdo->getAttribute($attribute); @@ -1004,7 +1004,7 @@ public function getAttribute(int $attribute): mixed * @param mixed $value * @return bool */ - public function setAttribute(int $attribute, mixed$value): bool + public function setAttribute(int $attribute, mixed $value): bool { $this->connect(); return $this->pdo->setAttribute($attribute, $value); diff --git a/src/PdoInterface.php b/src/PdoInterface.php index fbd6357e..6e86a687 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -146,7 +146,7 @@ public function query(string $query, ?int $fetchMode = null, ...$fetch_mode_args * * @param mixed $value The value to quote. * - * @param int $parameter_type A data type hint for the database driver. + * @param int $type A data type hint for the database driver. * * @return string|false The quoted value. * From e324cc0a0407191a8e3c13b1877e40304bd061a9 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Sun, 7 Nov 2021 10:29:10 +0000 Subject: [PATCH 22/23] update phpunit config --- phpunit.xml.dist | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a43a7acd..2e61e13e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,13 @@ - - - - ./tests - - - - - ./src - - + + + + + ./src + + + + + ./tests + + From fcd128a887a4a6aa5019abe04cf2b165009a9b60 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Sun, 7 Nov 2021 10:30:43 +0000 Subject: [PATCH 23/23] re-add PdoInterface::getAvailableDrivers() and add a test for this method. --- src/PdoInterface.php | 2 +- tests/ExtendedPdoTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PdoInterface.php b/src/PdoInterface.php index 6e86a687..a15f358d 100644 --- a/src/PdoInterface.php +++ b/src/PdoInterface.php @@ -186,5 +186,5 @@ public function setAttribute(int $attribute, mixed $value): bool; * @return array * */ - //public static function getAvailableDrivers(): array; + public static function getAvailableDrivers(): array; } diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index 68b331bb..463f33a1 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -741,4 +741,10 @@ public function testSetAttribute() $result = $this->pdo->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_NATURAL); $this->assertTrue($result); } + + public function testGetAvailableDrivers() + { + $drivers = $this->pdo::getAvailableDrivers(); + $this->assertTrue((bool)count($drivers)); + } }