From 8401cceb0daec6282b2c6cd20ef965592a322aa6 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 22 Jan 2018 16:04:29 -0500 Subject: [PATCH] Remove PDOInterface to prevent conflicts in method parameters with native PDO object --- phpstan.neon | 5 +- src/ConnectionManager.php | 13 +-- src/Drivers/AbstractDriver.php | 13 +-- src/Drivers/DriverInterface.php | 2 +- src/Drivers/PDOInterface.php | 146 -------------------------------- src/QueryBuilder.php | 10 --- tests/BaseDriverTest.php | 2 +- tests/BaseQueryBuilderTest.php | 3 + 8 files changed, 16 insertions(+), 178 deletions(-) delete mode 100644 src/Drivers/PDOInterface.php diff --git a/phpstan.neon b/phpstan.neon index eb20b2c..4367544 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,5 +2,6 @@ parameters: autoload_files: - %rootDir%/../../../tests/bootstrap.php ignoreErrors: - - '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#' - - '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#' + - '#Access to an undefined property Query\\QueryBuilderInterface::\$[a-zA-Z0-9_]+#' + - '#Call to an undefined method Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#' + - '#Call to an undefined method Query\\Drivers\\DriverInterface::[a-zA-Z0-9_]+\(\)#' diff --git a/src/ConnectionManager.php b/src/ConnectionManager.php index 81f76f0..dcf1c2a 100644 --- a/src/ConnectionManager.php +++ b/src/ConnectionManager.php @@ -31,9 +31,9 @@ final class ConnectionManager { /** * Class instance variable - * @var ConnectionManager + * @var ConnectionManager|null */ - private static $instance = NULL; + private static $instance; /** * Private constructor to prevent multiple instances @@ -62,7 +62,7 @@ final class ConnectionManager { */ public function __sleep() { - throw new DomainException("No serializing of singleton"); + throw new DomainException('No serializing of singleton'); } /** @@ -112,7 +112,7 @@ final class ConnectionManager { } // You should actually connect before trying to get a connection... - throw new InvalidArgumentException("The specified connection does not exist"); + throw new InvalidArgumentException('The specified connection does not exist'); } /** @@ -214,11 +214,6 @@ final class ConnectionManager { */ private function createDsn(string $dbtype, \stdClass $params): string { - if (strtolower($dbtype) === 'pdo_firebird') - { - $dbtype = 'firebird'; - } - $pairs = []; if ( ! empty($params->database)) diff --git a/src/Drivers/AbstractDriver.php b/src/Drivers/AbstractDriver.php index fda2f59..38a7fde 100644 --- a/src/Drivers/AbstractDriver.php +++ b/src/Drivers/AbstractDriver.php @@ -22,11 +22,10 @@ use PDOStatement; * Base Database class * * Extends PDO to simplify cross-database issues - * - * @package Query - * @subpackage Drivers */ -abstract class AbstractDriver extends PDO implements DriverInterface { +abstract class AbstractDriver + extends PDO + implements DriverInterface { /** * Reference to the last executed query @@ -536,11 +535,7 @@ abstract class AbstractDriver extends PDO implements DriverInterface { public function insertBatch($table, $data=[]) { $data = (array) $data; - $firstRow = current($data); - if (is_scalar($firstRow)) - { - return NULL; - } + $firstRow = (array) current($data); // Values for insertion $vals = []; diff --git a/src/Drivers/DriverInterface.php b/src/Drivers/DriverInterface.php index d608254..f257f6a 100644 --- a/src/Drivers/DriverInterface.php +++ b/src/Drivers/DriverInterface.php @@ -17,7 +17,7 @@ namespace Query\Drivers; /** * PDO Interface to implement for database drivers */ -interface DriverInterface extends PDOInterface { +interface DriverInterface { /** * Constructor/Connection method diff --git a/src/Drivers/PDOInterface.php b/src/Drivers/PDOInterface.php deleted file mode 100644 index 6518576..0000000 --- a/src/Drivers/PDOInterface.php +++ /dev/null @@ -1,146 +0,0 @@ - - * @copyright 2012 - 2018 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @link https://git.timshomepage.net/aviat4ion/Query - */ -namespace Query\Drivers; - -use PDO; -use PDOException; -use PDOStatement; - -/** - * Interface describing the PDO class in PHP - */ -interface PDOInterface { - - /** - * Creates a PDO instance representing a connection to a database - * - * @param string $dsn - * @param string $username - * @param string $password - * @param array $options - * @throws PDOException - */ - public function __construct($dsn, $username, $password, array $options = []); - - /** - * Initiates a transaction - * - * @throws PDOException - * @return boolean - */ - public function beginTransaction(); - - /** - * Commits a transaction - * - * @throws PDOException - * @return boolean - */ - public function commit(); - - /** - * Fetch the SQLSTATE associated with the last operation on the database handle - * - * @return mixed - */ - public function errorCode(); - - /** - * Fetch extended error information associated with the last operation on the database handle - * - * @return array - */ - public function errorInfo(); - - /** - * Execute an SQL statement and return the number of affected rows - * - * @param string $statement - * @return int - */ - public function exec($statement); - - /** - * Retrieve a database connection attribute - * - * @param int $attribute - * @return mixed - */ - public function getAttribute($attribute); - - /** - * Return an array of available PDO drivers - * - * @return array - */ - public static function getAvailableDrivers(); - - /** - * Checks if inside a transaction - * - * @return boolean - */ - public function inTransaction(); - - /** - * Returns teh ID of the last inserted row or sequence value - * - * @param string $name Name of the sequence object from which the ID should be returned - * @return string - */ - public function lastInsertId($name = NULL); - - /** - * Prepares a statement for execution and returns a statement object - * - * @param string $statement - * @param array $options - * @return PDOStatement - */ - public function prepare($statement, $options = NULL); - - /** - * Executes an SQL statement, returning a result set as a PDOStatement object - * - * @return PDOStatement - */ - public function query(); - - /** - * Quotes a string for use in a query - * - * @param string $string - * @param int $parameterType - * @return string|false - */ - public function quote($string, $parameterType = PDO::PARAM_STR); - - /** - * Rolls back a transaction - * - * @throws PDOException - * @return boolean - */ - public function rollBack(); - - /** - * Set an attribute - * - * @param int $attribute - * @param mixed $value - * @return boolean - */ - public function setAttribute($attribute, $value); -} diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index b7f30e8..39f0f0d 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -24,7 +24,6 @@ use Query\Drivers\{ /** * Convenience class for creating sql queries - * @method query(mixed $sql): PDOStatement; */ class QueryBuilder implements QueryBuilderInterface { @@ -274,15 +273,6 @@ class QueryBuilder implements QueryBuilderInterface { throw new BadMethodCallException('Method does not exist'); } - // -------------------------------------------------------------------------- - // ! Driver setters - // -------------------------------------------------------------------------- - - public function setDriver(DriverInterface $driver) - { - - } - // -------------------------------------------------------------------------- // ! Select Queries // -------------------------------------------------------------------------- diff --git a/tests/BaseDriverTest.php b/tests/BaseDriverTest.php index 85e58e6..c2fb152 100644 --- a/tests/BaseDriverTest.php +++ b/tests/BaseDriverTest.php @@ -22,7 +22,7 @@ namespace Query\Tests; abstract class BaseDriverTest extends TestCase { /** - * @var \Query\QueryBuilder + * @var \Query\QueryBuilderInterface|null */ protected static $db; diff --git a/tests/BaseQueryBuilderTest.php b/tests/BaseQueryBuilderTest.php index c950737..e682c45 100644 --- a/tests/BaseQueryBuilderTest.php +++ b/tests/BaseQueryBuilderTest.php @@ -21,6 +21,9 @@ use PDO; */ abstract class BaseQueryBuilderTest extends TestCase { + /** + * @var \Query\QueryBuilderInterface|null + */ protected static $db; public function __destruct()