Browse Source

Remove PDOInterface to prevent conflicts in method parameters with native PDO object

Timothy J. Warren 8 months ago
parent
commit
8401cceb0d

+ 3
- 2
phpstan.neon View File

@@ -2,5 +2,6 @@ parameters:
2 2
 	autoload_files:
3 3
 		- %rootDir%/../../../tests/bootstrap.php
4 4
 	ignoreErrors:
5
-		- '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#'
6
-		- '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#'
5
+		- '#Access to an undefined property Query\\QueryBuilderInterface::\$[a-zA-Z0-9_]+#'
6
+		- '#Call to an undefined method Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#'
7
+		- '#Call to an undefined method Query\\Drivers\\DriverInterface::[a-zA-Z0-9_]+\(\)#'

+ 4
- 9
src/ConnectionManager.php View File

@@ -31,9 +31,9 @@ final class ConnectionManager {
31 31
 
32 32
 	/**
33 33
 	 * Class instance variable
34
-	 * @var ConnectionManager
34
+	 * @var ConnectionManager|null
35 35
 	 */
36
-	private static $instance = NULL;
36
+	private static $instance;
37 37
 
38 38
 	/**
39 39
 	 * Private constructor to prevent multiple instances
@@ -62,7 +62,7 @@ final class ConnectionManager {
62 62
 	 */
63 63
 	public function __sleep()
64 64
 	{
65
-		throw new DomainException("No serializing of singleton");
65
+		throw new DomainException('No serializing of singleton');
66 66
 	}
67 67
 
68 68
 	/**
@@ -112,7 +112,7 @@ final class ConnectionManager {
112 112
 		}
113 113
 
114 114
 		// You should actually connect before trying to get a connection...
115
-		throw new InvalidArgumentException("The specified connection does not exist");
115
+		throw new InvalidArgumentException('The specified connection does not exist');
116 116
 	}
117 117
 
118 118
 	/**
@@ -214,11 +214,6 @@ final class ConnectionManager {
214 214
 	 */
215 215
 	private function createDsn(string $dbtype, \stdClass $params): string
216 216
 	{
217
-		if (strtolower($dbtype) === 'pdo_firebird')
218
-		{
219
-			$dbtype = 'firebird';
220
-		}
221
-
222 217
 		$pairs = [];
223 218
 
224 219
 		if ( ! empty($params->database))

+ 4
- 9
src/Drivers/AbstractDriver.php View File

@@ -22,11 +22,10 @@ use PDOStatement;
22 22
  * Base Database class
23 23
  *
24 24
  * Extends PDO to simplify cross-database issues
25
- *
26
- * @package Query
27
- * @subpackage Drivers
28 25
  */
29
-abstract class AbstractDriver extends PDO implements DriverInterface {
26
+abstract class AbstractDriver
27
+	extends PDO
28
+	implements DriverInterface {
30 29
 
31 30
 	/**
32 31
 	 * Reference to the last executed query
@@ -536,11 +535,7 @@ abstract class AbstractDriver extends PDO implements DriverInterface {
536 535
 	public function insertBatch($table, $data=[])
537 536
 	{
538 537
 		$data = (array) $data;
539
-		$firstRow = current($data);
540
-		if (is_scalar($firstRow))
541
-		{
542
-			return NULL;
543
-		}
538
+		$firstRow = (array) current($data);
544 539
 
545 540
 		// Values for insertion
546 541
 		$vals = [];

+ 1
- 1
src/Drivers/DriverInterface.php View File

@@ -17,7 +17,7 @@ namespace Query\Drivers;
17 17
 /**
18 18
  * PDO Interface to implement for database drivers
19 19
  */
20
-interface DriverInterface extends PDOInterface {
20
+interface DriverInterface {
21 21
 
22 22
 	/**
23 23
 	 * Constructor/Connection method

+ 0
- 146
src/Drivers/PDOInterface.php View File

@@ -1,146 +0,0 @@
1
-<?php declare(strict_types=1);
2
-/**
3
- * Query
4
- *
5
- * SQL Query Builder / Database Abstraction Layer
6
- *
7
- * PHP version 7.1
8
- *
9
- * @package     Query
10
- * @author      Timothy J. Warren <tim@timshomepage.net>
11
- * @copyright   2012 - 2018 Timothy J. Warren
12
- * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
13
- * @link        https://git.timshomepage.net/aviat4ion/Query
14
- */
15
-namespace Query\Drivers;
16
-
17
-use PDO;
18
-use PDOException;
19
-use PDOStatement;
20
-
21
-/**
22
- * Interface describing the PDO class in PHP
23
- */
24
-interface PDOInterface {
25
-
26
-	/**
27
-	 * Creates a PDO instance representing a connection to a database
28
-	 *
29
-	 * @param string $dsn
30
-	 * @param string $username
31
-	 * @param string $password
32
-	 * @param array $options
33
-	 * @throws PDOException
34
-	 */
35
-	public function __construct($dsn, $username, $password, array $options = []);
36
-
37
-	/**
38
-	 * Initiates a transaction
39
-	 *
40
-	 * @throws PDOException
41
-	 * @return boolean
42
-	 */
43
-	public function beginTransaction();
44
-
45
-	/**
46
-	 * Commits a transaction
47
-	 *
48
-	 * @throws PDOException
49
-	 * @return boolean
50
-	 */
51
-	public function commit();
52
-
53
-	/**
54
-	 * Fetch the SQLSTATE associated with the last operation on the database handle
55
-	 *
56
-	 * @return mixed
57
-	 */
58
-	public function errorCode();
59
-
60
-	/**
61
-	 * Fetch extended error information associated with the last operation on the database handle
62
-	 *
63
-	 * @return array
64
-	 */
65
-	public function errorInfo();
66
-
67
-	/**
68
-	 * Execute an SQL statement and return the number of affected rows
69
-	 *
70
-	 * @param string $statement
71
-	 * @return int
72
-	 */
73
-	public function exec($statement);
74
-
75
-	/**
76
-	 * Retrieve a database connection attribute
77
-	 *
78
-	 * @param int $attribute
79
-	 * @return mixed
80
-	 */
81
-	public function getAttribute($attribute);
82
-
83
-	/**
84
-	 * Return an array of available PDO drivers
85
-	 *
86
-	 * @return array
87
-	 */
88
-	public static function getAvailableDrivers();
89
-
90
-	/**
91
-	 * Checks if inside a transaction
92
-	 *
93
-	 * @return boolean
94
-	 */
95
-	public function inTransaction();
96
-
97
-	/**
98
-	 * Returns teh ID of the last inserted row or sequence value
99
-	 *
100
-	 * @param string $name Name of the sequence object from which the ID should be returned
101
-	 * @return string
102
-	 */
103
-	public function lastInsertId($name = NULL);
104
-
105
-	/**
106
-	 * Prepares a statement for execution and returns a statement object
107
-	 *
108
-	 * @param string $statement
109
-	 * @param array $options
110
-	 * @return PDOStatement
111
-	 */
112
-	public function prepare($statement, $options = NULL);
113
-
114
-	/**
115
-	 * Executes an SQL statement, returning a result set as a PDOStatement object
116
-	 *
117
-	 * @return PDOStatement
118
-	 */
119
-	public function query();
120
-
121
-	/**
122
-	 * Quotes a string for use in a query
123
-	 *
124
-	 * @param string $string
125
-	 * @param int $parameterType
126
-	 * @return string|false
127
-	 */
128
-	public function quote($string, $parameterType = PDO::PARAM_STR);
129
-
130
-	/**
131
-	 * Rolls back a transaction
132
-	 *
133
-	 * @throws PDOException
134
-	 * @return boolean
135
-	 */
136
-	public function rollBack();
137
-
138
-	/**
139
-	 * Set an attribute
140
-	 *
141
-	 * @param int $attribute
142
-	 * @param mixed $value
143
-	 * @return boolean
144
-	 */
145
-	public function setAttribute($attribute, $value);
146
-}

+ 0
- 10
src/QueryBuilder.php View File

@@ -24,7 +24,6 @@ use Query\Drivers\{
24 24
 
25 25
 /**
26 26
  * Convenience class for creating sql queries
27
- * @method query(mixed $sql): PDOStatement;
28 27
  */
29 28
 class QueryBuilder implements QueryBuilderInterface {
30 29
 
@@ -274,15 +273,6 @@ class QueryBuilder implements QueryBuilderInterface {
274 273
 		throw new BadMethodCallException('Method does not exist');
275 274
 	}
276 275
 
277
-	// --------------------------------------------------------------------------
278
-	// ! Driver setters
279
-	// --------------------------------------------------------------------------
280
-
281
-	public function setDriver(DriverInterface $driver)
282
-	{
283
-
284
-	}
285
-
286 276
 	// --------------------------------------------------------------------------
287 277
 	// ! Select Queries
288 278
 	// --------------------------------------------------------------------------

+ 1
- 1
tests/BaseDriverTest.php View File

@@ -22,7 +22,7 @@ namespace Query\Tests;
22 22
 abstract class BaseDriverTest extends TestCase {
23 23
 
24 24
 	/**
25
-	 * @var \Query\QueryBuilder
25
+	 * @var \Query\QueryBuilderInterface|null
26 26
 	 */
27 27
 	protected static $db;
28 28
 

+ 3
- 0
tests/BaseQueryBuilderTest.php View File

@@ -21,6 +21,9 @@ use PDO;
21 21
  */
22 22
 abstract class BaseQueryBuilderTest extends TestCase {
23 23
 
24
+	/**
25
+	 * @var \Query\QueryBuilderInterface|null
26
+	 */
24 27
 	protected static $db;
25 28
 
26 29
 	public function __destruct()