Browse Source

Code Style fixes

Timothy J. Warren 2 years ago
parent
commit
bb382131cc

+ 1
- 2
.travis.yml View File

@@ -3,11 +3,11 @@ sudo: false
3 3
 language: php
4 4
 
5 5
 php:
6
-  - 5.3
7 6
   - 5.4
8 7
   - 5.5
9 8
   - 5.6
10 9
   - 7
10
+  - 7.1
11 11
   - hhvm
12 12
   - nightly
13 13
 
@@ -28,7 +28,6 @@ after_script:
28 28
 
29 29
 matrix:
30 30
   allow_failures:
31
-    - php: 5.3
32 31
     - php: 5.4
33 32
     - php: 5.5
34 33
     - php: nightly

+ 5
- 23
LICENSE.md View File

@@ -1,27 +1,9 @@
1
-# DON'T BE A DICK PUBLIC LICENSE
1
+The MIT License (MIT)
2 2
 
3
-> Version 1, December 2009
3
+Copyright (c) 2016 Timothy J. Warren
4 4
 
5
-> Copyright (C) 2012 Timothy J. Warren <tim@timshomepage.net>
5
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 6
 
7
- Everyone is permitted to copy and distribute verbatim or modified
8
- copies of this license document, and changing it is allowed as long
9
- as the name is changed.
7
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 8
 
11
-> DON'T BE A DICK PUBLIC LICENSE
12
-> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
-
14
- 1. Do whatever you like with the original work, just don't be a dick.
15
-
16
-     Being a dick includes - but is not limited to - the following instances:
17
-
18
-	 1a. Outright copyright infringement - Don't just copy this and change the name.  
19
-	 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.  
20
-	 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.  
21
-
22
- 2. If you become rich through modifications, related works/services, or supporting the original work,
23
- share the love. Only a dick would make loads off this work and not buy the original work's
24
- creator(s) a pint.
25
-
26
- 3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
27
- you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
9
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 1
- 3
README.md View File

@@ -24,9 +24,6 @@ A query builder/database abstraction layer, using prepared statements for securi
24 24
 ## Including Query in your application
25 25
 
26 26
 * Install via composer and include `vendor/autoload.php`
27
-or
28
-* Just include the `autoload.php` file. This will automatically load the classes that are supported by the current PHP installation.
29
-
30 27
 
31 28
 ## Connecting
32 29
 
@@ -83,6 +80,7 @@ Query('old')->query($sql);
83 80
 
84 81
 ### Running Queries
85 82
 Query uses the same interface as CodeIgniter's [Query Builder](http://www.codeigniter.com/user_guide/database/query_builder.html) class. However, it does not implement the `update_batch` or caching methods. For specific query builder methods, see the [class documentation](https://gitdev.timshomepage.net/Query/docs/classes/Query_QueryBuilder.html#methods).
83
+Underscored methods are also aliased to camel case methods.
86 84
 
87 85
 #### You can also run queries manually.
88 86
 

+ 13
- 13
src/Query/AbstractDriver.php View File

@@ -65,7 +65,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
65 65
 
66 66
 	/**
67 67
 	 * Whether the driver supports 'TRUNCATE'
68
-	 * @var bool
68
+	 * @var boolean
69 69
 	 */
70 70
 	protected $has_truncate = TRUE;
71 71
 
@@ -77,7 +77,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
77 77
 	 * @param string $password
78 78
 	 * @param array $driver_options
79 79
 	 */
80
-	public function __construct($dsn, $username=NULL, $password=NULL, array $driver_options=array())
80
+	public function __construct($dsn, $username=NULL, $password=NULL, array $driver_options=[])
81 81
 	{
82 82
 		// Set PDO to display errors as exceptions, and apply driver options
83 83
 		$driver_options[\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_EXCEPTION;
@@ -117,7 +117,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
117 117
 	 * @param array $args
118 118
 	 * @return mixed
119 119
 	 */
120
-	public function __call($name, $args = array())
120
+	public function __call($name, $args = [])
121 121
 	{
122 122
 		if (
123 123
 			isset($this->$name)
@@ -125,7 +125,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
125 125
 			&& method_exists($this->$name, '__invoke')
126 126
 		)
127 127
 		{
128
-			return call_user_func_array(array($this->$name, '__invoke'), $args);
128
+			return call_user_func_array([$this->$name, '__invoke'], $args);
129 129
 		}
130 130
 	}
131 131
 
@@ -319,14 +319,14 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
319 319
 	{
320 320
 		if (is_array($ident))
321 321
 		{
322
-			return array_map(array($this, __METHOD__), $ident);
322
+			return array_map([$this, __METHOD__], $ident);
323 323
 		}
324 324
 
325 325
 		// Handle comma-separated identifiers
326 326
 		if (strpos($ident, ',') !== FALSE)
327 327
 		{
328 328
 			$parts = array_map('mb_trim', explode(',', $ident));
329
-			$parts = array_map(array($this, __METHOD__), $parts);
329
+			$parts = array_map([$this, __METHOD__], $parts);
330 330
 			$ident = implode(',', $parts);
331 331
 		}
332 332
 
@@ -335,10 +335,10 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
335 335
 		$hiers = array_map('mb_trim', $hiers);
336 336
 
337 337
 		// Re-compile the string
338
-		$raw = implode('.', array_map(array($this, '_quote'), $hiers));
338
+		$raw = implode('.', array_map([$this, '_quote'], $hiers));
339 339
 
340 340
 		// Fix functions
341
-		$funcs = array();
341
+		$funcs = [];
342 342
 		preg_match_all("#{$this->escape_char}([a-zA-Z0-9_]+(\((.*?)\))){$this->escape_char}#iu", $raw, $funcs, PREG_SET_ORDER);
343 343
 		foreach($funcs as $f)
344 344
 		{
@@ -561,7 +561,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
561 561
 	public function num_rows()
562 562
 	{
563 563
 		$regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
564
-		$output = array();
564
+		$output = [];
565 565
 
566 566
 		if (preg_match($regex, $this->last_query, $output) > 0)
567 567
 		{
@@ -581,7 +581,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
581 581
 	 * @param array $data
582 582
 	 * @return null|array<string|array|null>
583 583
 	 */
584
-	public function insert_batch($table, $data=array())
584
+	public function insert_batch($table, $data=[])
585 585
 	{
586 586
 		$first_row = current($data);
587 587
 		if ( ! is_array($first_row))
@@ -590,7 +590,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
590 590
 		}
591 591
 
592 592
 		// Values for insertion
593
-		$vals = array();
593
+		$vals = [];
594 594
 		foreach($data as $group)
595 595
 		{
596 596
 			$vals = array_merge($vals, array_values($group));
@@ -610,7 +610,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
610 610
 		// Append the placeholder groups to the query
611 611
 		$sql .= implode(',', $param_list);
612 612
 
613
-		return array($sql, $vals);
613
+		return [$sql, $vals];
614 614
 	}
615 615
 
616 616
 	// --------------------------------------------------------------------------
@@ -666,7 +666,7 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
666 666
 	public function truncate($table)
667 667
 	{
668 668
 		$sql = ($this->has_truncate)
669
-			? 'TRUNCATE '
669
+			? 'TRUNCATE TABLE '
670 670
 			: 'DELETE FROM ';
671 671
 
672 672
 		$sql .= $this->quote_table($table);

+ 24
- 24
src/Query/AbstractQueryBuilder.php View File

@@ -74,19 +74,19 @@ abstract class AbstractQueryBuilder {
74 74
 	 * Keys for insert/update statement
75 75
 	 * @var array
76 76
 	 */
77
-	protected $set_array_keys = array();
77
+	protected $set_array_keys = [];
78 78
 
79 79
 	/**
80 80
 	 * Key/val pairs for order by clause
81 81
 	 * @var array
82 82
 	 */
83
-	protected $order_array = array();
83
+	protected $order_array = [];
84 84
 
85 85
 	/**
86 86
 	 * Key/val pairs for group by clause
87 87
 	 * @var array
88 88
 	 */
89
-	protected $group_array = array();
89
+	protected $group_array = [];
90 90
 
91 91
 	// --------------------------------------------------------------------------
92 92
 	// ! Other Class vars
@@ -96,13 +96,13 @@ abstract class AbstractQueryBuilder {
96 96
 	 * Values to apply to prepared statements
97 97
 	 * @var array
98 98
 	 */
99
-	protected $values = array();
99
+	protected $values = [];
100 100
 
101 101
 	/**
102 102
 	 * Values to apply to where clauses in prepared statements
103 103
 	 * @var array
104 104
 	 */
105
-	protected $where_values = array();
105
+	protected $where_values = [];
106 106
 
107 107
 	/**
108 108
 	 * Value for limit string
@@ -112,7 +112,7 @@ abstract class AbstractQueryBuilder {
112 112
 
113 113
 	/**
114 114
 	 * Value for offset in limit string
115
-	 * @var int
115
+	 * @var integer
116 116
 	 */
117 117
 	protected $offset;
118 118
 
@@ -129,7 +129,7 @@ abstract class AbstractQueryBuilder {
129 129
 	 *
130 130
 	 * @var array
131 131
 	 */
132
-	protected $query_map = array();
132
+	protected $query_map = [];
133 133
 
134 134
 	/**
135 135
 	 * Map for having clause
@@ -151,7 +151,7 @@ abstract class AbstractQueryBuilder {
151 151
 
152 152
 	/**
153 153
 	 * Whether to do only an explain on the query
154
-	 * @var bool
154
+	 * @var boolean
155 155
 	 */
156 156
 	protected $explain;
157 157
 
@@ -195,12 +195,12 @@ abstract class AbstractQueryBuilder {
195 195
 	protected function _mixed_set(&$var, $key, $val=NULL, $val_type=self::BOTH)
196 196
 	{
197 197
 		$arg = (is_scalar($key) && is_scalar($val))
198
-			? array($key => $val)
198
+			? [$key => $val]
199 199
 			: $key;
200 200
 
201 201
 		foreach($arg as $k => $v)
202 202
 		{
203
-			if (in_array($val_type, array(self::KEY, self::VALUE)))
203
+			if (in_array($val_type, [self::KEY, self::VALUE]))
204 204
 			{
205 205
 				$var[] = ($val_type === self::KEY)
206 206
 					? $k
@@ -313,7 +313,7 @@ abstract class AbstractQueryBuilder {
313 313
 	 * @param string $conj
314 314
 	 * @return Query_Builder
315 315
 	 */
316
-	protected function _having($key, $val=array(), $conj='AND')
316
+	protected function _having($key, $val=[], $conj='AND')
317 317
 	{
318 318
 		$where = $this->_where($key, $val);
319 319
 
@@ -330,10 +330,10 @@ abstract class AbstractQueryBuilder {
330 330
 			$item .= (count($f_array) === 1) ? '=?' : " {$f_array[1]} ?";
331 331
 
332 332
 			// Put in the having map
333
-			$this->having_map[] = array(
333
+			$this->having_map[] = [
334 334
 				'conjunction' => ( ! empty($this->having_map)) ? " {$conj} " : ' HAVING ',
335 335
 				'string' => $item
336
-			);
336
+			];
337 337
 		}
338 338
 
339 339
 		return $this;
@@ -348,9 +348,9 @@ abstract class AbstractQueryBuilder {
348 348
 	 * @param mixed $val
349 349
 	 * @return array
350 350
 	 */
351
-	protected function _where($key, $val=array())
351
+	protected function _where($key, $val=[])
352 352
 	{
353
-		$where = array();
353
+		$where = [];
354 354
 		$this->_mixed_set($where, $key, $val, self::BOTH);
355 355
 		$this->_mixed_set($this->where_values, $key, $val, self::VALUE);
356 356
 		return $where;
@@ -366,7 +366,7 @@ abstract class AbstractQueryBuilder {
366 366
 	 * @param string $defaultConj
367 367
 	 * @return Query_Builder
368 368
 	 */
369
-	protected function _where_string($key, $val=array(), $defaultConj='AND')
369
+	protected function _where_string($key, $val=[], $defaultConj='AND')
370 370
 	{
371 371
 		// Create key/value placeholders
372 372
 		foreach($this->_where($key, $val) as $f => $val)
@@ -413,7 +413,7 @@ abstract class AbstractQueryBuilder {
413 413
 	 * @param string $conj - The where in conjunction
414 414
 	 * @return Query_Builder
415 415
 	 */
416
-	protected function _where_in($key, $val=array(), $in='IN', $conj='AND')
416
+	protected function _where_in($key, $val=[], $in='IN', $conj='AND')
417 417
 	{
418 418
 		$key = $this->db->quote_ident($key);
419 419
 		$params = array_fill(0, count($val), '?');
@@ -484,11 +484,11 @@ abstract class AbstractQueryBuilder {
484 484
 	 */
485 485
 	protected function _append_map($conjunction = '', $string = '', $type = '')
486 486
 	{
487
-		array_push($this->query_map, array(
487
+		array_push($this->query_map, [
488 488
 			'type' => $type,
489 489
 			'conjunction' => $conjunction,
490 490
 			'string' => $string
491
-		));
491
+		]);
492 492
 	}
493 493
 
494 494
 	// --------------------------------------------------------------------------
@@ -503,7 +503,7 @@ abstract class AbstractQueryBuilder {
503 503
 	 */
504 504
 	protected function _append_query($vals, $sql, $total_time)
505 505
 	{
506
-		$evals = (is_array($vals)) ? $vals : array();
506
+		$evals = (is_array($vals)) ? $vals : [];
507 507
 		$esql = str_replace('?', "%s", $sql);
508 508
 
509 509
 		// Quote string values
@@ -517,10 +517,10 @@ abstract class AbstractQueryBuilder {
517 517
 		array_unshift($evals, $esql);
518 518
 
519 519
 		// Add the interpreted query to the list of executed queries
520
-		$this->queries[] = array(
520
+		$this->queries[] = [
521 521
 			'time' => $total_time,
522 522
 			'sql' => call_user_func_array('sprintf', $evals),
523
-		);
523
+		];
524 524
 
525 525
 		$this->queries['total_time'] += $total_time;
526 526
 
@@ -584,12 +584,12 @@ abstract class AbstractQueryBuilder {
584 584
 		// Get the base clause for the query
585 585
 		$sql = $this->_compile_type($type, $this->db->quote_table($table));
586 586
 
587
-		$clauses = array(
587
+		$clauses = [
588 588
 			'query_map',
589 589
 			'group_string',
590 590
 			'order_string',
591 591
 			'having_map',
592
-		);
592
+		];
593 593
 
594 594
 		// Set each type of subclause
595 595
 		foreach($clauses as $clause)

+ 4
- 4
src/Query/AbstractUtil.php View File

@@ -65,7 +65,7 @@ abstract class AbstractUtil {
65 65
 	 * @param bool $if_not_exists
66 66
 	 * @return string
67 67
 	 */
68
-	public function create_table($name, $fields, array $constraints=array(), $if_not_exists=TRUE)
68
+	public function create_table($name, $fields, array $constraints=[], $if_not_exists=TRUE)
69 69
 	{
70 70
 		$exists_str = ($if_not_exists) ? ' IF NOT EXISTS ' : ' ';
71 71
 
@@ -75,13 +75,13 @@ abstract class AbstractUtil {
75 75
 		// 		'constraint' => ...,
76 76
 		// 		'index' => ...,
77 77
 		// )
78
-		$column_array = \array_zipper(array(
78
+		$column_array = \array_zipper([
79 79
 			'type' => $fields,
80 80
 			'constraint' => $constraints
81
-		));
81
+		]);
82 82
 
83 83
 		// Join column definitions together
84
-		$columns = array();
84
+		$columns = [];
85 85
 		foreach($column_array as $n => $props)
86 86
 		{
87 87
 			$str = $this->get_driver()->quote_ident($n);

+ 2
- 1
src/Query/BadDBDriverException.php View File

@@ -21,6 +21,7 @@ namespace Query;
21 21
  * @package Query
22 22
  * @subpackage Core
23 23
  */
24
-class BadDBDriverException extends \InvalidArgumentException {}
24
+class BadDBDriverException extends \InvalidArgumentException {
25
+}
25 26
 
26 27
 // End of BadDBDriverException.php

+ 18
- 12
src/Query/ConnectionManager.php View File

@@ -28,13 +28,13 @@ final class ConnectionManager {
28 28
 	 * Map of named database connections
29 29
 	 * @var array
30 30
 	 */
31
-	private $connections = array();
31
+	private $connections = [];
32 32
 
33 33
 	/**
34 34
 	 * Class instance variable
35
-	 * @var Connection_Manager
35
+	 * @var ConnectionManager
36 36
 	 */
37
-	private static $instance = null;
37
+	private static $instance = NULL;
38 38
 
39 39
 	// --------------------------------------------------------------------------
40 40
 
@@ -42,7 +42,9 @@ final class ConnectionManager {
42 42
 	 * Private constructor to prevent multiple instances
43 43
 	 * @codeCoverageIgnore
44 44
 	 */
45
-	private function __construct() {}
45
+	private function __construct() 
46
+ {
47
+ }
46 48
 
47 49
 	// --------------------------------------------------------------------------
48 50
 
@@ -87,7 +89,7 @@ final class ConnectionManager {
87 89
 	 */
88 90
 	public static function get_instance()
89 91
 	{
90
-		if (self::$instance === null)
92
+		if (self::$instance === NULL)
91 93
 		{
92 94
 			self::$instance = new self();
93 95
 		}
@@ -185,7 +187,7 @@ final class ConnectionManager {
185 187
 		}
186 188
 
187 189
 		// Set additional PDO options
188
-		$options = array();
190
+		$options = [];
189 191
 
190 192
 		if (isset($params->options))
191 193
 		{
@@ -201,13 +203,17 @@ final class ConnectionManager {
201 203
 		{
202 204
 			$dsn = $params->file;
203 205
 		}
206
+		else if(strtolower($dbtype) === 'oci')
207
+		{
208
+			$dsn = "dbname=//{$params->host}:{$params->port}/{$params->database}";
209
+		}
204 210
 		else
205 211
 		{
206 212
 			$dsn = $this->create_dsn($dbtype, $params);
207 213
 		}
208 214
 
209 215
 
210
-		return array($dsn, $dbtype, $params, $options);
216
+		return [$dsn, $dbtype, $params, $options];
211 217
 	}
212 218
 
213 219
 	// --------------------------------------------------------------------------
@@ -226,14 +232,14 @@ final class ConnectionManager {
226 232
 			$dbtype = 'firebird';
227 233
 		}
228 234
 
229
-		$pairs = array();
235
+		$pairs = [];
230 236
 
231 237
 		if ( ! empty($params->database))
232 238
 		{
233
-			$pairs[] = implode('=', array('dbname', $params->database));
239
+			$pairs[] = implode('=', ['dbname', $params->database]);
234 240
 		}
235 241
 
236
-		$skip = array(
242
+		$skip = [
237 243
 			'name' => 'name',
238 244
 			'pass' => 'pass',
239 245
 			'user' => 'user',
@@ -242,13 +248,13 @@ final class ConnectionManager {
242 248
 			'options' => 'options',
243 249
 			'database' => 'database',
244 250
 			'alias' => 'alias'
245
-		);
251
+		];
246 252
 
247 253
 		foreach($params as $key => $val)
248 254
 		{
249 255
 			if (( ! array_key_exists($key, $skip)) && ( ! empty($val)))
250 256
 			{
251
-				$pairs[] = implode('=', array($key, $val));
257
+				$pairs[] = implode('=', [$key, $val]);
252 258
 			}
253 259
 		}
254 260
 

+ 2
- 2
src/Query/DriverInterface.php View File

@@ -31,7 +31,7 @@ interface DriverInterface {
31 31
 	 * @param string $password
32 32
 	 * @param array $driver_options
33 33
 	 */
34
-	public function __construct($dsn, $username=NULL, $password=NULL, array $driver_options = array());
34
+	public function __construct($dsn, $username=NULL, $password=NULL, array $driver_options = []);
35 35
 
36 36
 	/**
37 37
 	 * Simplifies prepared statements for database queries
@@ -268,6 +268,6 @@ interface DriverInterface {
268 268
 	 * @param array $data
269 269
 	 * @return array
270 270
 	 */
271
-	public function insert_batch($table, $data=array());
271
+	public function insert_batch($table, $data=[]);
272 272
 }
273 273
 // End of driver_interface.php

+ 7
- 7
src/Query/Drivers/Firebird/Driver.php View File

@@ -64,7 +64,7 @@ class Driver extends \Query\AbstractDriver {
64 64
 	/**
65 65
 	 * Firebird doesn't have the truncate keyword
66 66
 	 *
67
-	 * @var bool
67
+	 * @var boolean
68 68
 	 */
69 69
 	protected $has_truncate = FALSE;
70 70
 
@@ -77,7 +77,7 @@ class Driver extends \Query\AbstractDriver {
77 77
 	 * @param array $options
78 78
 	 * @throws \PDOException
79 79
 	 */
80
-	public function __construct($dbpath, $user='SYSDBA', $pass='masterkey', array $options = array())
80
+	public function __construct($dbpath, $user='SYSDBA', $pass='masterkey', array $options = [])
81 81
 	{
82 82
 		$connect_function = (isset($options[\PDO::ATTR_PERSISTENT]) && $options[\PDO::ATTR_PERSISTENT])
83 83
 			? '\\fbird_pconnect'
@@ -217,7 +217,7 @@ class Driver extends \Query\AbstractDriver {
217 217
 	 * @return Result
218 218
 	 * @throws \PDOException
219 219
 	 */
220
-	public function prepare($query, $options=array())
220
+	public function prepare($query, $options=[])
221 221
 	{
222 222
 		$this->statement_link = \fbird_prepare($this->conn, $query);
223 223
 
@@ -335,7 +335,7 @@ class Driver extends \Query\AbstractDriver {
335 335
 		$code = \fbird_errcode();
336 336
 		$msg = \fbird_errmsg();
337 337
 
338
-		return array(0, $code, $msg);
338
+		return [0, $code, $msg];
339 339
 	}
340 340
 
341 341
 	// --------------------------------------------------------------------------
@@ -375,7 +375,7 @@ class Driver extends \Query\AbstractDriver {
375 375
 	 * @param array $data
376 376
 	 * @return array
377 377
 	 */
378
-	public function insert_batch($table, $data=array())
378
+	public function insert_batch($table, $data=[])
379 379
 	{
380 380
 		// Each member of the data array needs to be an array
381 381
 		if ( ! is_array(current($data)))
@@ -396,7 +396,7 @@ class Driver extends \Query\AbstractDriver {
396 396
 		foreach($data as $item)
397 397
 		{
398 398
 			// Quote string values
399
-			$vals = array_map(array($this, 'quote'), $item);
399
+			$vals = array_map([$this, 'quote'], $item);
400 400
 
401 401
 			// Add the values in the sql
402 402
 			$sql .= $insert_template . implode(', ', $vals) . ");\n";
@@ -408,7 +408,7 @@ class Driver extends \Query\AbstractDriver {
408 408
 		// Return a null array value so the query is run as it is,
409 409
 		// not as a prepared statement, because a prepared statement
410 410
 		// doesn't work for this type of query in Firebird.
411
-		return array($sql, NULL);
411
+		return [$sql, NULL];
412 412
 	}
413 413
 }
414 414
 // End of firebird_driver.php

+ 5
- 5
src/Query/Drivers/Firebird/Result.php View File

@@ -34,7 +34,7 @@ class Result extends \PDOStatement {
34 34
 	/**
35 35
 	 * Current row in result array
36 36
 	 *
37
-	 * @var int
37
+	 * @var integer
38 38
 	 */
39 39
 	private $row;
40 40
 
@@ -43,7 +43,7 @@ class Result extends \PDOStatement {
43 43
 	 *
44 44
 	 * @param mixed
45 45
 	 */
46
-	private $result = array();
46
+	private $result = [];
47 47
 
48 48
 	/**
49 49
 	 * Reference to the db drive to de-duplicate error functions
@@ -68,7 +68,7 @@ class Result extends \PDOStatement {
68 68
 		$this->statement = $link;
69 69
 		$this->setFetchMode(\PDO::FETCH_ASSOC);
70 70
 		$this->row = -1;
71
-		$this->result = array();
71
+		$this->result = [];
72 72
 
73 73
 		// Create the result array, so that we can get row counts
74 74
 		// Check the resource type, because prepared statements are "interbase query"
@@ -212,7 +212,7 @@ class Result extends \PDOStatement {
212 212
 	 */
213 213
 	public function fetchAll($fetch_style=\PDO::FETCH_ASSOC, $statement=NULL, $ctor_args=NULL)
214 214
 	{
215
-		$all = array();
215
+		$all = [];
216 216
 
217 217
 		while($row = $this->fetch($fetch_style, $statement))
218 218
 		{
@@ -247,7 +247,7 @@ class Result extends \PDOStatement {
247 247
 	 * @param array $ctor_args
248 248
 	 * @return stdClass
249 249
 	 */
250
-	public function fetchObject($class_name='stdClass', $ctor_args=array())
250
+	public function fetchObject($class_name='stdClass', $ctor_args=[])
251 251
 	{
252 252
 		return $this->fetch(\PDO::FETCH_OBJ);
253 253
 	}

+ 4
- 4
src/Query/Drivers/Firebird/Util.php View File

@@ -33,7 +33,7 @@ class Util extends \Query\AbstractUtil {
33 33
 	 * @param bool $if_not_exists
34 34
 	 * @return string
35 35
 	 */
36
-	public function create_table($name, $fields, array $constraints=array(), $if_not_exists=FALSE)
36
+	public function create_table($name, $fields, array $constraints=[], $if_not_exists=FALSE)
37 37
 	{
38 38
 		return parent::create_table($name, $fields, $constraints, FALSE);
39 39
 	}
@@ -73,7 +73,7 @@ class Util extends \Query\AbstractUtil {
73 73
 	 * @param bool $system_tables
74 74
 	 * @return string
75 75
 	 */
76
-	public function backup_data($exclude=array(), $system_tables=FALSE)
76
+	public function backup_data($exclude=[], $system_tables=FALSE)
77 77
 	{
78 78
 		// Determine which tables to use
79 79
 		$tables = $this->get_driver()->get_tables();
@@ -106,7 +106,7 @@ class Util extends \Query\AbstractUtil {
106 106
 			// Nab the column names by getting the keys of the first row
107 107
 			$columns = @array_keys($obj_res[0]);
108 108
 
109
-			$insert_rows = array();
109
+			$insert_rows = [];
110 110
 
111 111
 			// Create the insert statements
112 112
 			foreach($obj_res as $row)
@@ -116,7 +116,7 @@ class Util extends \Query\AbstractUtil {
116 116
 				// Quote values as needed by type
117 117
 				if(stripos($t, 'RDB$') === FALSE)
118 118
 				{
119
-					$row = array_map(array($this->get_driver(), 'quote'), $row);
119
+					$row = array_map([$this->get_driver(), 'quote'], $row);
120 120
 					$row = array_map('trim', $row);
121 121
 				}
122 122
 

+ 3
- 3
src/Query/Drivers/Mysql/Driver.php View File

@@ -39,14 +39,14 @@ class Driver extends \Query\AbstractDriver {
39 39
 	 * @param string $password
40 40
 	 * @param array $options
41 41
 	 */
42
-	public function __construct($dsn, $username=null, $password=null, array $options=array())
42
+	public function __construct($dsn, $username=NULL, $password=NULL, array $options=[])
43 43
 	{
44 44
 		// Set the charset to UTF-8
45 45
 		if (defined('\\PDO::MYSQL_ATTR_INIT_COMMAND'))
46 46
 		{
47
-			$options = array_merge($options, array(
47
+			$options = array_merge($options, [
48 48
 				\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF-8 COLLATE 'UTF-8'",
49
-			));
49
+			]);
50 50
 		}
51 51
 
52 52
 		if (strpos($dsn, 'mysql') === FALSE)

+ 3
- 3
src/Query/Drivers/Mysql/Util.php View File

@@ -30,7 +30,7 @@ class Util extends \Query\AbstractUtil {
30 30
 	 */
31 31
 	public function backup_structure()
32 32
 	{
33
-		$string = array();
33
+		$string = [];
34 34
 
35 35
 		// Get databases
36 36
 		$dbs = $this->get_driver()->get_dbs();
@@ -72,7 +72,7 @@ class Util extends \Query\AbstractUtil {
72 72
 	 * @param array $exclude
73 73
 	 * @return string
74 74
 	 */
75
-	public function backup_data($exclude=array())
75
+	public function backup_data($exclude=[])
76 76
 	{
77 77
 		$tables = $this->get_driver()->get_tables();
78 78
 
@@ -100,7 +100,7 @@ class Util extends \Query\AbstractUtil {
100 100
 			// Nab the column names by getting the keys of the first row
101 101
 			$columns = @array_keys($rows[0]);
102 102
 
103
-			$insert_rows = array();
103
+			$insert_rows = [];
104 104
 
105 105
 			// Create the insert statements
106 106
 			foreach($rows as $row)

+ 4
- 4
src/Query/Drivers/Pgsql/Driver.php View File

@@ -32,7 +32,7 @@ class Driver extends \Query\AbstractDriver {
32 32
 	 * @param string $password
33 33
 	 * @param array  $options
34 34
 	 */
35
-	public function __construct($dsn, $username=null, $password=null, array $options=array())
35
+	public function __construct($dsn, $username=NULL, $password=NULL, array $options=[])
36 36
 	{
37 37
 		if (strpos($dsn, 'pgsql') === FALSE)
38 38
 		{
@@ -70,16 +70,16 @@ SQL;
70 70
 	 */
71 71
 	public function get_fks($table)
72 72
 	{
73
-		$value_map = array(
73
+		$value_map = [
74 74
 			'c' => 'CASCADE',
75 75
 			'r' => 'RESTRICT',
76
-		);
76
+		];
77 77
 
78 78
 		$keys = parent::get_fks($table);
79 79
 
80 80
 		foreach($keys as &$key)
81 81
 		{
82
-			foreach(array('update', 'delete') AS $type)
82
+			foreach(['update', 'delete'] AS $type)
83 83
 			{
84 84
 				if ( ! isset($value_map[$key[$type]]))
85 85
 				{

+ 3
- 3
src/Query/Drivers/Pgsql/Util.php View File

@@ -42,7 +42,7 @@ class Util extends \Query\AbstractUtil {
42 42
 	 * @param array $exclude
43 43
 	 * @return string
44 44
 	 */
45
-	public function backup_data($exclude=array())
45
+	public function backup_data($exclude=[])
46 46
 	{
47 47
 		$tables = $this->get_driver()->get_tables();
48 48
 
@@ -72,7 +72,7 @@ class Util extends \Query\AbstractUtil {
72 72
 			// Nab the column names by getting the keys of the first row
73 73
 			$columns = @array_keys($obj_res[0]);
74 74
 
75
-			$insert_rows = array();
75
+			$insert_rows = [];
76 76
 
77 77
 			// Create the insert statements
78 78
 			foreach($obj_res as $row)
@@ -80,7 +80,7 @@ class Util extends \Query\AbstractUtil {
80 80
 				$row = array_values($row);
81 81
 
82 82
 				// Quote values as needed by type
83
-				$row = array_map(array($this->get_driver(), 'quote'), $row);
83
+				$row = array_map([$this->get_driver(), 'quote'], $row);
84 84
 				$row = array_map('trim', $row);
85 85
 
86 86
 

+ 9
- 9
src/Query/Drivers/Sqlite/Driver.php View File

@@ -33,7 +33,7 @@ class Driver extends \Query\AbstractDriver {
33 33
 	/**
34 34
 	 * SQLite has a truncate optimization,
35 35
 	 * but no support for the actual keyword
36
-	 * @var bool
36
+	 * @var boolean
37 37
 	 */
38 38
 	protected $has_truncate = FALSE;
39 39
 
@@ -45,7 +45,7 @@ class Driver extends \Query\AbstractDriver {
45 45
 	 * @param string $pass
46 46
 	 * @param array $driver_options
47 47
 	 */
48
-	public function __construct($dsn, $user=NULL, $pass=NULL, array $driver_options=array())
48
+	public function __construct($dsn, $user=NULL, $pass=NULL, array $driver_options=[])
49 49
 	{
50 50
 		if (strpos($dsn, 'sqlite:') === FALSE)
51 51
 		{
@@ -80,17 +80,17 @@ class Driver extends \Query\AbstractDriver {
80 80
 	 */
81 81
 	public function get_fks($table)
82 82
 	{
83
-		$return_rows = array();
83
+		$return_rows = [];
84 84
 
85 85
 		foreach(parent::get_fks($table) as $row)
86 86
 		{
87
-			$return_rows[] = array(
87
+			$return_rows[] = [
88 88
 				'child_column' => $row['from'],
89 89
 				'parent_table' => $row['table'],
90 90
 				'parent_column' => $row['to'],
91 91
 				'update' => $row['on_update'],
92 92
 				'delete' => $row['on_delete']
93
-			);
93
+			];
94 94
 		}
95 95
 
96 96
 		return $return_rows;
@@ -106,7 +106,7 @@ class Driver extends \Query\AbstractDriver {
106 106
 	 * @param array $data
107 107
 	 * @return string
108 108
 	 */
109
-	public function insert_batch($table, $data=array())
109
+	public function insert_batch($table, $data=[])
110 110
 	{
111 111
 		// If greater than version 3.7.11, supports the same syntax as
112 112
 		// MySQL and Postgres
@@ -131,7 +131,7 @@ class Driver extends \Query\AbstractDriver {
131 131
 
132 132
 		// Create a key-value mapping for each field
133 133
 		$first = array_shift($data);
134
-		$cols = array();
134
+		$cols = [];
135 135
 		foreach($first as $colname => $datum)
136 136
 		{
137 137
 			$cols[] = $this->_quote($datum) . ' AS ' . $this->quote_ident($colname);
@@ -140,11 +140,11 @@ class Driver extends \Query\AbstractDriver {
140 140
 
141 141
 		foreach($data as $union)
142 142
 		{
143
-			$vals = array_map(array($this, 'quote'), $union);
143
+			$vals = array_map([$this, 'quote'], $union);
144 144
 			$sql .= "UNION SELECT " . implode(',', $vals) . "\n";
145 145
 		}
146 146
 
147
-		return array($sql, NULL);
147
+		return [$sql, NULL];
148 148
 	}
149 149
 }
150 150
 //End of sqlite_driver.php

+ 2
- 2
src/Query/Drivers/Sqlite/SQL.php View File

@@ -85,7 +85,7 @@ SQL;
85 85
 	 */
86 86
 	public function system_table_list()
87 87
 	{
88
-		return array('sqlite_master', 'sqlite_temp_master', 'sqlite_sequence');
88
+		return ['sqlite_master', 'sqlite_temp_master', 'sqlite_sequence'];
89 89
 	}
90 90
 
91 91
 	// --------------------------------------------------------------------------
@@ -159,7 +159,7 @@ SQL;
159 159
 	 */
160 160
 	public function type_list()
161 161
 	{
162
-		return array('INTEGER', 'REAL', 'TEXT', 'BLOB');
162
+		return ['INTEGER', 'REAL', 'TEXT', 'BLOB'];
163 163
 	}
164 164
 
165 165
 	// --------------------------------------------------------------------------

+ 3
- 3
src/Query/Drivers/Sqlite/Util.php View File

@@ -31,7 +31,7 @@ class Util extends \Query\AbstractUtil {
31 31
 	 * @param array $excluded
32 32
 	 * @return string
33 33
 	 */
34
-	public function backup_data($excluded=array())
34
+	public function backup_data($excluded=[])
35 35
 	{
36 36
 		// Get a list of all the objects
37 37
 		$sql = 'SELECT DISTINCT "name"
@@ -68,7 +68,7 @@ class Util extends \Query\AbstractUtil {
68 68
 			// Nab the column names by getting the keys of the first row
69 69
 			$columns = array_keys(current($obj_res));
70 70
 
71
-			$insert_rows = array();
71
+			$insert_rows = [];
72 72
 
73 73
 			// Create the insert statements
74 74
 			foreach($obj_res as $row)
@@ -110,7 +110,7 @@ class Util extends \Query\AbstractUtil {
110 110
 		$res = $this->get_driver()->query($sql);
111 111
 		$result = $res->fetchAll(\PDO::FETCH_ASSOC);
112 112
 
113
-		$sql_array = array();
113
+		$sql_array = [];
114 114
 
115 115
 		foreach($result as $r)
116 116
 		{

+ 24
- 24
src/Query/QueryBuilder.php View File

@@ -24,14 +24,14 @@ namespace Query;
24 24
  * @package Query
25 25
  * @subpackage Query_Builder
26 26
  */
27
-class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface {
27
+class QueryBuilder extends AbstractQueryBuilder /*implements QueryBuilderInterface*/ {
28 28
 
29 29
 	/**
30 30
 	 * String class values to be reset
31 31
 	 *
32 32
 	 * @var array
33 33
 	 */
34
-	private $string_vars = array(
34
+	private $string_vars = [
35 35
 		'select_string',
36 36
 		'from_string',
37 37
 		'set_string',
@@ -40,14 +40,14 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
40 40
 		'limit',
41 41
 		'offset',
42 42
 		'explain',
43
-	);
43
+	];
44 44
 
45 45
 	/**
46 46
 	 * Array class variables to be reset
47 47
 	 *
48 48
 	 * @var array
49 49
 	 */
50
-	private $array_vars = array(
50
+	private $array_vars = [
51 51
 		'set_array_keys',
52 52
 		'order_array',
53 53
 		'group_array',
@@ -55,7 +55,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
55 55
 		'where_values',
56 56
 		'query_map',
57 57
 		'having_map'
58
-	);
58
+	];
59 59
 
60 60
 	// --------------------------------------------------------------------------
61 61
 	// ! Methods
@@ -106,13 +106,13 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
106 106
 		// Allow camel-case method calls
107 107
 		$snake_name = \from_camel_case($name);
108 108
 
109
-		foreach(array($this, $this->db) as $object)
109
+		foreach([$this, $this->db] as $object)
110 110
 		{
111
-			foreach(array($name, $snake_name) as $method_name)
111
+			foreach([$name, $snake_name] as $method_name)
112 112
 			{
113 113
 				if (method_exists($object, $method_name))
114 114
 				{
115
-					return call_user_func_array(array($object, $method_name), $params);
115
+					return call_user_func_array([$object, $method_name], $params);
116 116
 				}
117 117
 			}
118 118
 
@@ -356,7 +356,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
356 356
 	 * @param mixed $val
357 357
 	 * @return QueryBuilder
358 358
 	 */
359
-	public function having($key, $val=array())
359
+	public function having($key, $val=[])
360 360
 	{
361 361
 		return $this->_having($key, $val, 'AND');
362 362
 	}
@@ -370,7 +370,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
370 370
 	 * @param mixed $val
371 371
 	 * @return QueryBuilder
372 372
 	 */
373
-	public function or_having($key, $val=array())
373
+	public function or_having($key, $val=[])
374 374
 	{
375 375
 		return $this->_having($key, $val, 'OR');
376 376
 	}
@@ -389,7 +389,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
389 389
 	 * @param mixed $escape
390 390
 	 * @return QueryBuilder
391 391
 	 */
392
-	public function where($key, $val=array(), $escape=NULL)
392
+	public function where($key, $val=[], $escape=NULL)
393 393
 	{
394 394
 		return $this->_where_string($key, $val, 'AND');
395 395
 	}
@@ -403,7 +403,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
403 403
 	 * @param mixed $val
404 404
 	 * @return QueryBuilder
405 405
 	 */
406
-	public function or_where($key, $val=array())
406
+	public function or_where($key, $val=[])
407 407
 	{
408 408
 		return $this->_where_string($key, $val, 'OR');
409 409
 	}
@@ -417,7 +417,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
417 417
 	 * @param mixed $val
418 418
 	 * @return QueryBuilder
419 419
 	 */
420
-	public function where_in($field, $val=array())
420
+	public function where_in($field, $val=[])
421 421
 	{
422 422
 		return $this->_where_in($field, $val);
423 423
 	}
@@ -431,7 +431,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
431 431
 	 * @param mixed $val
432 432
 	 * @return QueryBuilder
433 433
 	 */
434
-	public function or_where_in($field, $val=array())
434
+	public function or_where_in($field, $val=[])
435 435
 	{
436 436
 		return $this->_where_in($field, $val, 'IN', 'OR');
437 437
 	}
@@ -445,7 +445,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
445 445
 	 * @param mixed $val
446 446
 	 * @return QueryBuilder
447 447
 	 */
448
-	public function where_not_in($field, $val=array())
448
+	public function where_not_in($field, $val=[])
449 449
 	{
450 450
 		return $this->_where_in($field, $val, 'NOT IN', 'AND');
451 451
 	}
@@ -459,7 +459,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
459 459
 	 * @param mixed $val
460 460
 	 * @return QueryBuilder
461 461
 	 */
462
-	public function or_where_not_in($field, $val=array())
462
+	public function or_where_not_in($field, $val=[])
463 463
 	{
464 464
 		return $this->_where_in($field, $val, 'NOT IN', 'OR');
465 465
 	}
@@ -482,7 +482,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
482 482
 
483 483
 		// Use the keys of the array to make the insert/update string
484 484
 		// Escape the field names
485
-		$this->set_array_keys = array_map(array($this->db, '_quote'), $this->set_array_keys);
485
+		$this->set_array_keys = array_map([$this->db, '_quote'], $this->set_array_keys);
486 486
 
487 487
 		// Generate the "set" string
488 488
 		$this->set_string = implode('=?,', $this->set_array_keys);
@@ -530,7 +530,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
530 530
 	{
531 531
 		if ( ! is_scalar($field))
532 532
 		{
533
-			$new_group_array = array_map(array($this->db, 'quote_ident'), $field);
533
+			$new_group_array = array_map([$this->db, 'quote_ident'], $field);
534 534
 			$this->group_array = array_merge($this->group_array, $new_group_array);
535 535
 		}
536 536
 		else
@@ -566,7 +566,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
566 566
 		$field = $this->db->quote_ident($field);
567 567
 		$this->order_array[$field] = $type;
568 568
 
569
-		$order_clauses = array();
569
+		$order_clauses = [];
570 570
 
571 571
 		// Flatten key/val pairs into an array of space-separated pairs
572 572
 		foreach($this->order_array as $k => $v)
@@ -702,7 +702,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
702 702
 	 * @param int|bool $offset
703 703
 	 * @return \PDOStatement
704 704
 	 */
705
-	public function get_where($table, $where=array(), $limit=FALSE, $offset=FALSE)
705
+	public function get_where($table, $where=[], $limit=FALSE, $offset=FALSE)
706 706
 	{
707 707
 		// Create the where clause
708 708
 		$this->where($where);
@@ -758,7 +758,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
758 758
 	 * @param mixed $data
759 759
 	 * @return \PDOStatement
760 760
 	 */
761
-	public function insert($table, $data=array())
761
+	public function insert($table, $data=[])
762 762
 	{
763 763
 		if ( ! empty($data))
764 764
 		{
@@ -777,7 +777,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
777 777
 	 * @param array $data
778 778
 	 * @return \PDOStatement
779 779
 	 */
780
-	public function insert_batch($table, $data=array())
780
+	public function insert_batch($table, $data=[])
781 781
 	{
782 782
 		// Get the generated values and sql string
783 783
 		list($sql, $data) = $this->db->insert_batch($table, $data);
@@ -796,7 +796,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
796 796
 	 * @param mixed $data
797 797
 	 * @return \PDOStatement
798 798
 	 */
799
-	public function update($table, $data=array())
799
+	public function update($table, $data=[])
800 800
 	{
801 801
 		if ( ! empty($data))
802 802
 		{
@@ -913,7 +913,7 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
913 913
 		// Reset arrays
914 914
 		foreach($this->array_vars as $var)
915 915
 		{
916
-			$this->$var = array();
916
+			$this->$var = [];
917 917
 		}
918 918
 	}
919 919
 }

+ 78
- 43
src/Query/QueryBuilderInterface.php View File

@@ -31,7 +31,7 @@ interface QueryBuilderInterface {
31 31
 	 * Specifies rows to select in a query
32 32
 	 *
33 33
 	 * @param string $fields
34
-	 * @return QueryBuilder
34
+	 * @return QueryBuilderInterface
35 35
 	 */
36 36
 	public function select($fields);
37 37
 
@@ -42,7 +42,7 @@ interface QueryBuilderInterface {
42 42
 	 *
43 43
 	 * @param string $field
44 44
 	 * @param string|bool $as
45
-	 * @return QueryBuilder
45
+	 * @return QueryBuilderInterface
46 46
 	 */
47 47
 	public function select_max($field, $as=FALSE);
48 48
 
@@ -53,7 +53,7 @@ interface QueryBuilderInterface {
53 53
 	 *
54 54
 	 * @param string $field
55 55
 	 * @param string|bool $as
56
-	 * @return QueryBuilder
56
+	 * @return QueryBuilderInterface
57 57
 	 */
58 58
 	public function select_min($field, $as=FALSE);
59 59
 
@@ -64,7 +64,7 @@ interface QueryBuilderInterface {
64 64
 	 *
65 65
 	 * @param string $field
66 66
 	 * @param string|bool $as
67
-	 * @return QueryBuilder
67
+	 * @return QueryBuilderInterface
68 68
 	 */
69 69
 	public function select_avg($field, $as=FALSE);
70 70
 
@@ -75,7 +75,7 @@ interface QueryBuilderInterface {
75 75
 	 *
76 76
 	 * @param string $field
77 77
 	 * @param string|bool $as
78
-	 * @return QueryBuilder
78
+	 * @return QueryBuilderInterface
79 79
 	 */
80 80
 	public function select_sum($field, $as=FALSE);
81 81
 
@@ -84,7 +84,7 @@ interface QueryBuilderInterface {
84 84
 	/**
85 85
 	 * Adds the 'distinct' keyword to a query
86 86
 	 *
87
-	 * @return QueryBuilder
87
+	 * @return QueryBuilderInterface
88 88
 	 */
89 89
 	public function distinct();
90 90
 
@@ -93,7 +93,7 @@ interface QueryBuilderInterface {
93 93
 	/**
94 94
 	 * Shows the query plan for the query
95 95
 	 *
96
-	 * @return QueryBuilder
96
+	 * @return QueryBuilderInterface
97 97
 	 */
98 98
 	public function explain();
99 99
 
@@ -103,7 +103,7 @@ interface QueryBuilderInterface {
103 103
 	 * Specify the database table to select from
104 104
 	 *
105 105
 	 * @param string $tblname
106
-	 * @return QueryBuilder
106
+	 * @return QueryBuilderInterface
107 107
 	 */
108 108
 	public function from($tblname);
109 109
 
@@ -117,7 +117,7 @@ interface QueryBuilderInterface {
117 117
 	 * @param string $field
118 118
 	 * @param mixed $val
119 119
 	 * @param string $pos
120
-	 * @return QueryBuilder
120
+	 * @return QueryBuilderInterface
121 121
 	 */
122 122
 	public function like($field, $val, $pos='both');
123 123
 
@@ -129,7 +129,7 @@ interface QueryBuilderInterface {
129 129
 	 * @param string $field
130 130
 	 * @param mixed $val
131 131
 	 * @param string $pos
132
-	 * @return QueryBuilder
132
+	 * @return QueryBuilderInterface
133 133
 	 */
134 134
 	public function or_like($field, $val, $pos='both');
135 135
 
@@ -141,7 +141,7 @@ interface QueryBuilderInterface {
141 141
 	 * @param string $field
142 142
 	 * @param mixed $val
143 143
 	 * @param string $pos
144
-	 * @return QueryBuilder
144
+	 * @return QueryBuilderInterface
145 145
 	 */
146 146
 	public function not_like($field, $val, $pos='both');
147 147
 
@@ -153,7 +153,7 @@ interface QueryBuilderInterface {
153 153
 	 * @param string $field
154 154
 	 * @param mixed $val
155 155
 	 * @param string $pos
156
-	 * @return QueryBuilder
156
+	 * @return QueryBuilderInterface
157 157
 	 */
158 158
 	public function or_not_like($field, $val, $pos='both');
159 159
 
@@ -166,9 +166,9 @@ interface QueryBuilderInterface {
166 166
 	 *
167 167
 	 * @param mixed $key
168 168
 	 * @param mixed $val
169
-	 * @return QueryBuilder
169
+	 * @return QueryBuilderInterface
170 170
 	 */
171
-	public function having($key, $val=array());
171
+	public function having($key, $val=[]);
172 172
 
173 173
 	// --------------------------------------------------------------------------
174 174
 
@@ -177,9 +177,9 @@ interface QueryBuilderInterface {
177 177
 	 *
178 178
 	 * @param mixed $key
179 179
 	 * @param mixed $val
180
-	 * @return QueryBuilder
180
+	 * @return QueryBuilderInterface
181 181
 	 */
182
-	public function or_having($key, $val=array());
182
+	public function or_having($key, $val=[]);
183 183
 
184 184
 	// --------------------------------------------------------------------------
185 185
 	// ! 'Where' methods
@@ -193,9 +193,9 @@ interface QueryBuilderInterface {
193 193
 	 * @param mixed $key
194 194
 	 * @param mixed $val
195 195
 	 * @param bool $escape
196
-	 * @return QueryBuilder
196
+	 * @return QueryBuilderInterface
197 197
 	 */
198
-	public function where($key, $val=array(), $escape = NULL);
198
+	public function where($key, $val=[], $escape = NULL);
199 199
 
200 200
 	// --------------------------------------------------------------------------
201 201
 
@@ -204,9 +204,9 @@ interface QueryBuilderInterface {
204 204
 	 *
205 205
 	 * @param string $key
206 206
 	 * @param mixed $val
207
-	 * @return QueryBuilder
207
+	 * @return QueryBuilderInterface
208 208
 	 */
209
-	public function or_where($key, $val=array());
209
+	public function or_where($key, $val=[]);
210 210
 
211 211
 	// --------------------------------------------------------------------------
212 212
 
@@ -215,9 +215,9 @@ interface QueryBuilderInterface {
215 215
 	 *
216 216
 	 * @param mixed $field
217 217
 	 * @param mixed $val
218
-	 * @return QueryBuilder
218
+	 * @return QueryBuilderInterface
219 219
 	 */
220
-	public function where_in($field, $val=array());
220
+	public function where_in($field, $val=[]);
221 221
 
222 222
 	// --------------------------------------------------------------------------
223 223
 
@@ -226,9 +226,9 @@ interface QueryBuilderInterface {
226 226
 	 *
227 227
 	 * @param string $field
228 228
 	 * @param mixed $val
229
-	 * @return QueryBuilder
229
+	 * @return QueryBuilderInterface
230 230
 	 */
231
-	public function or_where_in($field, $val=array());
231
+	public function or_where_in($field, $val=[]);
232 232
 
233 233
 	// --------------------------------------------------------------------------
234 234
 
@@ -237,9 +237,9 @@ interface QueryBuilderInterface {
237 237
 	 *
238 238
 	 * @param string $field
239 239
 	 * @param mixed $val
240
-	 * @return QueryBuilder
240
+	 * @return QueryBuilderInterface
241 241
 	 */
242
-	public function where_not_in($field, $val=array());
242
+	public function where_not_in($field, $val=[]);
243 243
 
244 244
 	// --------------------------------------------------------------------------
245 245
 
@@ -248,9 +248,9 @@ interface QueryBuilderInterface {
248 248
 	 *
249 249
 	 * @param string $field
250 250
 	 * @param mixed $val
251
-	 * @return QueryBuilder
251
+	 * @return QueryBuilderInterface
252 252
 	 */
253
-	public function or_where_not_in($field, $val=array());
253
+	public function or_where_not_in($field, $val=[]);
254 254
 
255 255
 	// --------------------------------------------------------------------------
256 256
 	// ! Other Query Modifier methods
@@ -261,7 +261,7 @@ interface QueryBuilderInterface {
261 261
 	 *
262 262
 	 * @param mixed $key
263 263
 	 * @param mixed $val
264
-	 * @return QueryBuilder
264
+	 * @return QueryBuilderInterface
265 265
 	 */
266 266
 	public function set($key, $val = NULL);
267 267
 
@@ -273,7 +273,7 @@ interface QueryBuilderInterface {
273 273
 	 * @param string $table
274 274
 	 * @param string $condition
275 275
 	 * @param string $type
276
-	 * @return QueryBuilder
276
+	 * @return QueryBuilderInterface
277 277
 	 */
278 278
 	public function join($table, $condition, $type='');
279 279
 
@@ -283,7 +283,7 @@ interface QueryBuilderInterface {
283 283
 	 * Group the results by the selected field(s)
284 284
 	 *
285 285
 	 * @param mixed $field
286
-	 * @return QueryBuilder
286
+	 * @return QueryBuilderInterface
287 287
 	 */
288 288
 	public function group_by($field);
289 289
 
@@ -294,7 +294,7 @@ interface QueryBuilderInterface {
294 294
 	 *
295 295
 	 * @param string $field
296 296
 	 * @param string $type
297
-	 * @return QueryBuilder
297
+	 * @return QueryBuilderInterface
298 298
 	 */
299 299
 	public function order_by($field, $type="");
300 300
 
@@ -305,7 +305,7 @@ interface QueryBuilderInterface {
305 305
 	 *
306 306
 	 * @param int $limit
307 307
 	 * @param int|bool $offset
308
-	 * @return QueryBuilder
308
+	 * @return QueryBuilderInterface
309 309
 	 */
310 310
 	public function limit($limit, $offset=FALSE);
311 311
 
@@ -316,17 +316,27 @@ interface QueryBuilderInterface {
316 316
 	/**
317 317
 	 * Adds a paren to the current query for query grouping
318 318
 	 *
319
-	 * @return QueryBuilder
319
+	 * @return QueryBuilderInterface
320 320
 	 */
321 321
 	public function group_start();
322 322
 
323 323
 	// --------------------------------------------------------------------------
324 324
 
325
+	/**
326
+	 * Adds a paren to the current query for query grouping,
327
+	 * prefixed with 'NOT'
328
+	 * 
329
+	 * @return QueryBuilderInterface
330
+	 */
331
+	public function not_group_start();
332
+
333
+	// --------------------------------------------------------------------------
334
+
325 335
 	/**
326 336
 	 * Adds a paren to the current query for query grouping,
327 337
 	 * prefixed with 'OR'
328 338
 	 *
329
-	 * @return QueryBuilder
339
+	 * @return QueryBuilderInterface
330 340
 	 */
331 341
 	public function or_group_start();
332 342
 
@@ -336,7 +346,7 @@ interface QueryBuilderInterface {
336 346
 	 * Adds a paren to the current query for query grouping,
337 347
 	 * prefixed with 'OR NOT'
338 348
 	 *
339
-	 * @return QueryBuilder
349
+	 * @return QueryBuilderInterface
340 350
 	 */
341 351
 	public function or_not_group_start();
342 352
 
@@ -345,7 +355,7 @@ interface QueryBuilderInterface {
345 355
 	/**
346 356
 	 * Ends a query group
347 357
 	 *
348
-	 * @return QueryBuilder
358
+	 * @return QueryBuilderInterface
349 359
 	 */
350 360
 	public function group_end();
351 361
 
@@ -375,7 +385,7 @@ interface QueryBuilderInterface {
375 385
 	 * @param int|bool $offset
376 386
 	 * @return \PDOStatement
377 387
 	 */
378
-	public function get_where($table, $where=array(), $limit=FALSE, $offset=FALSE);
388
+	public function get_where($table, $where=[], $limit=FALSE, $offset=FALSE);
379 389
 
380 390
 	// --------------------------------------------------------------------------
381 391
 
@@ -394,9 +404,10 @@ interface QueryBuilderInterface {
394 404
 	 * in place of the get() method
395 405
 	 *
396 406
 	 * @param string $table
407
+	 * @param bool $reset - Whether to keep the query after counting the results
397 408
 	 * @return int
398 409
 	 */
399
-	public function count_all_results($table='');
410
+	public function count_all_results($table='', $reset=TRUE);
400 411
 
401 412
 	// --------------------------------------------------------------------------
402 413
 
@@ -407,7 +418,7 @@ interface QueryBuilderInterface {
407 418
 	 * @param mixed $data
408 419
 	 * @return \PDOStatement
409 420
 	 */
410
-	public function insert($table, $data=array());
421
+	public function insert($table, $data=[]);
411 422
 
412 423
 	// --------------------------------------------------------------------------
413 424
 
@@ -418,7 +429,18 @@ interface QueryBuilderInterface {
418 429
 	 * @param array $data
419 430
 	 * @return \PDOStatement|null
420 431
 	 */
421
-	public function insert_batch($table, $data=array());
432
+	public function insert_batch($table, $data=[]);
433
+
434
+	// --------------------------------------------------------------------------
435
+
436
+	/**
437
+	 * Insertion with automatic overwrite, rather than attempted duplication
438
+	 *
439
+	 * @param string $table
440
+	 * @param array $data
441
+	 * @return \PDOStatement|null
442
+	 */
443
+	public function replace($table, $data=[]);
422 444
 
423 445
 	// --------------------------------------------------------------------------
424 446
 
@@ -429,7 +451,20 @@ interface QueryBuilderInterface {
429 451
 	 * @param mixed $data
430 452
 	 * @return \PDOStatement
431 453
 	 */
432
-	public function update($table, $data=array());
454
+	public function update($table, $data=[]);
455
+
456
+	// --------------------------------------------------------------------------
457
+
458
+	/**
459
+	 * Creates a batch update, and executes it.
460
+	 * Returns the number of affected rows
461
+	 *
462
+	 * @param string $table
463
+	 * @param array|object $data
464
+	 * @param string $where
465
+	 * @return int
466
+	 */
467
+	public function update_batch($table, $data, $where);
433 468
 
434 469
 	// --------------------------------------------------------------------------
435 470
 
@@ -500,4 +535,4 @@ interface QueryBuilderInterface {
500 535
 	public function reset_query();
501 536
 }
502 537
 
503
-// End of QueryBuilder_interface.php
538
+// End of QueryBuilderInterface.php

+ 10
- 10
src/Query/QueryParser.php View File

@@ -35,23 +35,23 @@ class QueryParser {
35 35
 	 *
36 36
 	 * @var array
37 37
 	 */
38
-	private $match_patterns = array(
38
+	private $match_patterns = [
39 39
 		'function' => '([a-zA-Z0-9_]+\((.*?)\))',
40 40
 		'identifier' => '([a-zA-Z0-9_-]+\.?)+',
41 41
 		'operator' => '=|AND|&&?|~|\|\|?|\^|/|>=?|<=?|-|%|OR|\+|NOT|\!=?|<>|XOR'
42
-	);
42
+	];
43 43
 
44 44
 	/**
45 45
 	 * Regex matches
46 46
 	 *
47 47
 	 * @var array
48 48
 	 */
49
-	public $matches = array(
50
-		'functions' => array(),
51
-		'identifiers' => array(),
52
-		'operators' => array(),
53
-		'combined' => array(),
54
-	);
49
+	public $matches = [
50
+		'functions' => [],
51
+		'identifiers' => [],
52
+		'operators' => [],
53
+		'combined' => [],
54
+	];
55 55
 
56 56
 	/**
57 57
 	 * Constructor/entry point into parser
@@ -83,7 +83,7 @@ class QueryParser {
83 83
 		preg_match_all($full_pattern, $sql, $this->matches['combined'], PREG_SET_ORDER);
84 84
 
85 85
 		// Go through the matches, and get the most relevant matches
86
-		$this->matches = array_map(array($this, 'filter_array'), $this->matches);
86
+		$this->matches = array_map([$this, 'filter_array'], $this->matches);
87 87
 
88 88
 		return $this->matches;
89 89
 	}
@@ -123,7 +123,7 @@ class QueryParser {
123 123
 	 */
124 124
 	protected function filter_array($array)
125 125
 	{
126
-		$new_array = array();
126
+		$new_array = [];
127 127
 
128 128
 		foreach($array as $row)
129 129
 		{