Passed
Branch 1.0.0-dev (c78053)
by nguereza
04:10 queued 15s
created
core/classes/Database.php 1 patch
Spacing   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -23,165 +23,165 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class Database{
26
+  class Database {
27 27
 	
28 28
 	/**
29 29
 	 * The PDO instance
30 30
 	 * @var object
31 31
 	*/
32
-    private $pdo                 = null;
32
+    private $pdo = null;
33 33
     
34 34
 	/**
35 35
 	 * The database name used for the application
36 36
 	 * @var string
37 37
 	*/
38
-	private $databaseName        = null;
38
+	private $databaseName = null;
39 39
     
40 40
 	/**
41 41
 	 * The SQL SELECT statment
42 42
 	 * @var string
43 43
 	*/
44
-	private $select              = '*';
44
+	private $select = '*';
45 45
 	
46 46
 	/**
47 47
 	 * The SQL FROM statment
48 48
 	 * @var string
49 49
 	*/
50
-    private $from                = null;
50
+    private $from = null;
51 51
 	
52 52
 	/**
53 53
 	 * The SQL WHERE statment
54 54
 	 * @var string
55 55
 	*/
56
-    private $where               = null;
56
+    private $where = null;
57 57
 	
58 58
 	/**
59 59
 	 * The SQL LIMIT statment
60 60
 	 * @var string
61 61
 	*/
62
-    private $limit               = null;
62
+    private $limit = null;
63 63
 	
64 64
 	/**
65 65
 	 * The SQL JOIN statment
66 66
 	 * @var string
67 67
 	*/
68
-    private $join                = null;
68
+    private $join = null;
69 69
 	
70 70
 	/**
71 71
 	 * The SQL ORDER BY statment
72 72
 	 * @var string
73 73
 	*/
74
-    private $orderBy             = null;
74
+    private $orderBy = null;
75 75
 	
76 76
 	/**
77 77
 	 * The SQL GROUP BY statment
78 78
 	 * @var string
79 79
 	*/
80
-    private $groupBy             = null;
80
+    private $groupBy = null;
81 81
 	
82 82
 	/**
83 83
 	 * The SQL HAVING statment
84 84
 	 * @var string
85 85
 	*/
86
-    private $having              = null;
86
+    private $having = null;
87 87
 	
88 88
 	/**
89 89
 	 * The number of rows returned by the last query
90 90
 	 * @var int
91 91
 	*/
92
-    private $numRows             = 0;
92
+    private $numRows = 0;
93 93
 	
94 94
 	/**
95 95
 	 * The last insert id for the primary key column that have auto increment or sequence
96 96
 	 * @var mixed
97 97
 	*/
98
-    private $insertId            = null;
98
+    private $insertId = null;
99 99
 	
100 100
 	/**
101 101
 	 * The full SQL query statment after build for each command
102 102
 	 * @var string
103 103
 	*/
104
-    private $query               = null;
104
+    private $query = null;
105 105
 	
106 106
 	/**
107 107
 	 * The error returned for the last query
108 108
 	 * @var string
109 109
 	*/
110
-    private $error               = null;
110
+    private $error = null;
111 111
 	
112 112
 	/**
113 113
 	 * The result returned for the last query
114 114
 	 * @var mixed
115 115
 	*/
116
-    private $result              = array();
116
+    private $result = array();
117 117
 	
118 118
 	/**
119 119
 	 * The prefix used in each database table
120 120
 	 * @var string
121 121
 	*/
122
-    private $prefix              = null;
122
+    private $prefix = null;
123 123
 	
124 124
 	/**
125 125
 	 * The list of SQL valid operators
126 126
 	 * @var array
127 127
 	*/
128
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
128
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
129 129
     
130 130
 	/**
131 131
 	 * The cache default time to live in second. 0 means no need to use the cache feature
132 132
 	 * @var int
133 133
 	*/
134
-	private $cacheTtl              = 0;
134
+	private $cacheTtl = 0;
135 135
 	
136 136
 	/**
137 137
 	 * The cache current time to live. 0 means no need to use the cache feature
138 138
 	 * @var int
139 139
 	*/
140
-    private $temporaryCacheTtl   = 0;
140
+    private $temporaryCacheTtl = 0;
141 141
 	
142 142
 	/**
143 143
 	 * The number of executed query for the current request
144 144
 	 * @var int
145 145
 	*/
146
-    private $queryCount          = 0;
146
+    private $queryCount = 0;
147 147
 	
148 148
 	/**
149 149
 	 * The default data to be used in the statments query INSERT, UPDATE
150 150
 	 * @var array
151 151
 	*/
152
-    private $data                = array();
152
+    private $data = array();
153 153
 	
154 154
 	/**
155 155
 	 * The database configuration
156 156
 	 * @var array
157 157
 	*/
158
-    private $config              = array();
158
+    private $config = array();
159 159
 	
160 160
 	/**
161 161
 	 * The logger instance
162 162
 	 * @var Log
163 163
 	 */
164
-    private $logger              = null;
164
+    private $logger = null;
165 165
 
166 166
 
167 167
     /**
168 168
     * The cache instance
169 169
     * @var CacheInterface
170 170
     */
171
-    private $cacheInstance       = null;
171
+    private $cacheInstance = null;
172 172
 
173 173
      /**
174 174
     * The benchmark instance
175 175
     * @var Benchmark
176 176
     */
177
-    private $benchmarkInstance   = null;
177
+    private $benchmarkInstance = null;
178 178
 
179 179
 
180 180
     /**
181 181
      * Construct new database
182 182
      * @param array $overwriteConfig the config to overwrite with the config set in database.php
183 183
      */
184
-    public function __construct($overwriteConfig = array()){
184
+    public function __construct($overwriteConfig = array()) {
185 185
         //Set Log instance to use
186 186
         $this->setLoggerFromParamOrCreateNewInstance(null);
187 187
 
@@ -197,23 +197,23 @@  discard block
 block discarded – undo
197 197
      * This is used to connect to database
198 198
      * @return bool 
199 199
      */
200
-    public function connect(){
200
+    public function connect() {
201 201
       $config = $this->getDatabaseConfiguration();
202
-      if (! empty($config)){
203
-        try{
202
+      if (!empty($config)) {
203
+        try {
204 204
             $this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
205 205
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
206 206
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
207 207
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
208 208
             return true;
209 209
           }
210
-          catch (PDOException $e){
210
+          catch (PDOException $e) {
211 211
             $this->logger->fatal($e->getMessage());
212 212
             show_error('Cannot connect to Database.');
213 213
             return false;
214 214
           }
215 215
       }
216
-      else{
216
+      else {
217 217
         show_error('Database configuration is not set.');
218 218
         return false;
219 219
       }
@@ -224,15 +224,15 @@  discard block
 block discarded – undo
224 224
      * @param  string|array $table the table name or array of table list
225 225
      * @return object        the current Database instance
226 226
      */
227
-    public function from($table){
228
-      if (is_array($table)){
227
+    public function from($table) {
228
+      if (is_array($table)) {
229 229
         $froms = '';
230
-        foreach($table as $key){
230
+        foreach ($table as $key) {
231 231
           $froms .= $this->prefix . $key . ', ';
232 232
         }
233 233
         $this->from = rtrim($froms, ', ');
234 234
       }
235
-      else{
235
+      else {
236 236
         $this->from = $this->prefix . $table;
237 237
       }
238 238
       return $this;
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      * @param  string|array $fields the field name or array of field list
244 244
      * @return object        the current Database instance
245 245
      */
246
-    public function select($fields){
246
+    public function select($fields) {
247 247
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
248 248
       $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select);
249 249
       return $this;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      * @param  string $field the field name to distinct
255 255
      * @return object        the current Database instance
256 256
      */
257
-    public function distinct($field){
257
+    public function distinct($field) {
258 258
       $distinct = ' DISTINCT ' . $field;
259 259
       $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct);
260 260
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
      * @param  string $name  if is not null represent the alias used for this field in the result
268 268
      * @return object        the current Database instance
269 269
      */
270
-    public function max($field, $name = null){
270
+    public function max($field, $name = null) {
271 271
       $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
272 272
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
273 273
       return $this;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      * @param  string $name  if is not null represent the alias used for this field in the result
280 280
      * @return object        the current Database instance
281 281
      */
282
-    public function min($field, $name = null){
282
+    public function min($field, $name = null) {
283 283
       $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
284 284
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
285 285
       return $this;
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @param  string $name  if is not null represent the alias used for this field in the result
292 292
      * @return object        the current Database instance
293 293
      */
294
-    public function sum($field, $name = null){
294
+    public function sum($field, $name = null) {
295 295
       $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
296 296
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
297 297
       return $this;
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      * @param  string $name  if is not null represent the alias used for this field in the result
304 304
      * @return object        the current Database instance
305 305
      */
306
-    public function count($field = '*', $name = null){
306
+    public function count($field = '*', $name = null) {
307 307
       $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
308 308
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
309 309
       return $this;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      * @param  string $name  if is not null represent the alias used for this field in the result
316 316
      * @return object        the current Database instance
317 317
      */
318
-    public function avg($field, $name = null){
318
+    public function avg($field, $name = null) {
319 319
       $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
320 320
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
321 321
       return $this;
@@ -330,16 +330,16 @@  discard block
 block discarded – undo
330 330
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
331 331
      * @return object        the current Database instance
332 332
      */
333
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
333
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
334 334
       $on = $field1;
335 335
       $table = $this->prefix . $table;
336
-      if (! is_null($op)){
337
-        $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
336
+      if (!is_null($op)) {
337
+        $on = (!in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
338 338
       }
339
-      if (empty($this->join)){
339
+      if (empty($this->join)) {
340 340
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
341 341
       }
342
-      else{
342
+      else {
343 343
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
344 344
       }
345 345
       return $this;
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      * @see  Database::join()
351 351
      * @return object        the current Database instance
352 352
      */
353
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
353
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
354 354
       return $this->join($table, $field1, $op, $field2, 'INNER ');
355 355
     }
356 356
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
      * @see  Database::join()
360 360
      * @return object        the current Database instance
361 361
      */
362
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
362
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
363 363
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
364 364
 	}
365 365
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      * @see  Database::join()
369 369
      * @return object        the current Database instance
370 370
      */
371
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
371
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
372 372
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
373 373
     }
374 374
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      * @see  Database::join()
378 378
      * @return object        the current Database instance
379 379
      */
380
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
380
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
381 381
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
382 382
     }
383 383
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
      * @see  Database::join()
387 387
      * @return object        the current Database instance
388 388
      */
389
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
389
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
390 390
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
391 391
     }
392 392
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
      * @see  Database::join()
396 396
      * @return object        the current Database instance
397 397
      */
398
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
398
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
399 399
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
400 400
     }
401 401
 
@@ -405,14 +405,14 @@  discard block
 block discarded – undo
405 405
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
406 406
      * @return object        the current Database instance
407 407
      */
408
-    public function whereIsNull($field, $andOr = 'AND'){
409
-      if (is_array($field)){
410
-        foreach($field as $f){
408
+    public function whereIsNull($field, $andOr = 'AND') {
409
+      if (is_array($field)) {
410
+        foreach ($field as $f) {
411 411
         	$this->whereIsNull($f, $andOr);
412 412
         }
413 413
       }
414
-      else{
415
-           $this->setWhereStr($field.' IS NULL ', $andOr);
414
+      else {
415
+           $this->setWhereStr($field . ' IS NULL ', $andOr);
416 416
       }
417 417
       return $this;
418 418
     }
@@ -423,14 +423,14 @@  discard block
 block discarded – undo
423 423
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
424 424
      * @return object        the current Database instance
425 425
      */
426
-    public function whereIsNotNull($field, $andOr = 'AND'){
427
-      if (is_array($field)){
428
-        foreach($field as $f){
426
+    public function whereIsNotNull($field, $andOr = 'AND') {
427
+      if (is_array($field)) {
428
+        foreach ($field as $f) {
429 429
           $this->whereIsNotNull($f, $andOr);
430 430
         }
431 431
       }
432
-      else{
433
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
432
+      else {
433
+          $this->setWhereStr($field . ' IS NOT NULL ', $andOr);
434 434
       }
435 435
       return $this;
436 436
     }
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
      * @param  boolean $escape whether to escape or not the $val
446 446
      * @return object        the current Database instance
447 447
      */
448
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
448
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
449 449
       $whereStr = '';
450
-      if (is_array($where)){
450
+      if (is_array($where)) {
451 451
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
452 452
       }
453
-      else{
454
-        if (is_array($op)){
453
+      else {
454
+        if (is_array($op)) {
455 455
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
456 456
         } else {
457 457
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
      * @see  Database::where()
467 467
      * @return object        the current Database instance
468 468
      */
469
-    public function orWhere($where, $op = null, $val = null, $escape = true){
469
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
470 470
       return $this->where($where, $op, $val, '', 'OR', $escape);
471 471
     }
472 472
 
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
      * @see  Database::where()
477 477
      * @return object        the current Database instance
478 478
      */
479
-    public function notWhere($where, $op = null, $val = null, $escape = true){
479
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
480 480
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
481 481
     }
482 482
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
      * @see  Database::where()
486 486
      * @return object        the current Database instance
487 487
      */
488
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
488
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
489 489
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
490 490
     }
491 491
 
@@ -495,15 +495,15 @@  discard block
 block discarded – undo
495 495
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
496 496
      * @return object        the current Database instance
497 497
      */
498
-    public function groupStart($type = '', $andOr = ' AND'){
499
-      if (empty($this->where)){
498
+    public function groupStart($type = '', $andOr = ' AND') {
499
+      if (empty($this->where)) {
500 500
         $this->where = $type . ' (';
501 501
       }
502
-      else{
503
-          if (substr($this->where, -1) == '('){
502
+      else {
503
+          if (substr($this->where, -1) == '(') {
504 504
             $this->where .= $type . ' (';
505 505
           }
506
-          else{
506
+          else {
507 507
           	$this->where .= $andOr . ' ' . $type . ' (';
508 508
           }
509 509
       }
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
      * @see  Database::groupStart()
516 516
      * @return object        the current Database instance
517 517
      */
518
-    public function notGroupStart(){
518
+    public function notGroupStart() {
519 519
       return $this->groupStart('NOT');
520 520
     }
521 521
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
      * @see  Database::groupStart()
525 525
      * @return object        the current Database instance
526 526
      */
527
-    public function orGroupStart(){
527
+    public function orGroupStart() {
528 528
       return $this->groupStart('', ' OR');
529 529
     }
530 530
 
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
      * @see  Database::groupStart()
534 534
      * @return object        the current Database instance
535 535
      */
536
-    public function orNotGroupStart(){
536
+    public function orNotGroupStart() {
537 537
       return $this->groupStart('NOT', ' OR');
538 538
     }
539 539
 
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
      * Close the parenthesis for the grouped SQL
542 542
      * @return object        the current Database instance
543 543
      */
544
-    public function groupEnd(){
544
+    public function groupEnd() {
545 545
       $this->where .= ')';
546 546
       return $this;
547 547
     }
@@ -555,10 +555,10 @@  discard block
 block discarded – undo
555 555
      * @param  boolean $escape whether to escape or not the values
556 556
      * @return object        the current Database instance
557 557
      */
558
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
558
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
559 559
       $_keys = array();
560
-      foreach ($keys as $k => $v){
561
-        if (is_null($v)){
560
+      foreach ($keys as $k => $v) {
561
+        if (is_null($v)) {
562 562
           $v = '';
563 563
         }
564 564
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      * @see  Database::in()
575 575
      * @return object        the current Database instance
576 576
      */
577
-    public function notIn($field, array $keys, $escape = true){
577
+    public function notIn($field, array $keys, $escape = true) {
578 578
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
579 579
     }
580 580
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
      * @see  Database::in()
584 584
      * @return object        the current Database instance
585 585
      */
586
-    public function orIn($field, array $keys, $escape = true){
586
+    public function orIn($field, array $keys, $escape = true) {
587 587
       return $this->in($field, $keys, '', 'OR', $escape);
588 588
     }
589 589
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      * @see  Database::in()
593 593
      * @return object        the current Database instance
594 594
      */
595
-    public function orNotIn($field, array $keys, $escape = true){
595
+    public function orNotIn($field, array $keys, $escape = true) {
596 596
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
597 597
     }
598 598
 
@@ -606,11 +606,11 @@  discard block
 block discarded – undo
606 606
      * @param  boolean $escape whether to escape or not the values
607 607
      * @return object        the current Database instance
608 608
      */
609
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
610
-      if (is_null($value1)){
609
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
610
+      if (is_null($value1)) {
611 611
         $value1 = '';
612 612
       }
613
-      if (is_null($value2)){
613
+      if (is_null($value2)) {
614 614
         $value2 = '';
615 615
       }
616 616
       $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
      * @see  Database::between()
624 624
      * @return object        the current Database instance
625 625
      */
626
-    public function notBetween($field, $value1, $value2, $escape = true){
626
+    public function notBetween($field, $value1, $value2, $escape = true) {
627 627
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
628 628
     }
629 629
 
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
      * @see  Database::between()
633 633
      * @return object        the current Database instance
634 634
      */
635
-    public function orBetween($field, $value1, $value2, $escape = true){
635
+    public function orBetween($field, $value1, $value2, $escape = true) {
636 636
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
637 637
     }
638 638
 
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
      * @see  Database::between()
642 642
      * @return object        the current Database instance
643 643
      */
644
-    public function orNotBetween($field, $value1, $value2, $escape = true){
644
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
645 645
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
646 646
     }
647 647
 
@@ -654,8 +654,8 @@  discard block
 block discarded – undo
654 654
      * @param  boolean $escape whether to escape or not the values
655 655
      * @return object        the current Database instance
656 656
      */
657
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
658
-      if (empty($data)){
657
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
658
+      if (empty($data)) {
659 659
         $data = '';
660 660
       }
661 661
       $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
      * @see  Database::like()
668 668
      * @return object        the current Database instance
669 669
      */
670
-    public function orLike($field, $data, $escape = true){
670
+    public function orLike($field, $data, $escape = true) {
671 671
       return $this->like($field, $data, '', 'OR', $escape);
672 672
     }
673 673
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
      * @see  Database::like()
677 677
      * @return object        the current Database instance
678 678
      */
679
-    public function notLike($field, $data, $escape = true){
679
+    public function notLike($field, $data, $escape = true) {
680 680
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
681 681
     }
682 682
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
      * @see  Database::like()
686 686
      * @return object        the current Database instance
687 687
      */
688
-    public function orNotLike($field, $data, $escape = true){
688
+    public function orNotLike($field, $data, $escape = true) {
689 689
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
690 690
     }
691 691
 
@@ -696,14 +696,14 @@  discard block
 block discarded – undo
696 696
      * @param  int $limitEnd the limit count
697 697
      * @return object        the current Database instance
698 698
      */
699
-    public function limit($limit, $limitEnd = null){
700
-      if (empty($limit)){
699
+    public function limit($limit, $limitEnd = null) {
700
+      if (empty($limit)) {
701 701
         return;
702 702
       }
703
-      if (! is_null($limitEnd)){
703
+      if (!is_null($limitEnd)) {
704 704
         $this->limit = $limit . ', ' . $limitEnd;
705 705
       }
706
-      else{
706
+      else {
707 707
         $this->limit = $limit;
708 708
       }
709 709
       return $this;
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
      * @param  string $orderDir the order direction (ASC or DESC)
716 716
      * @return object        the current Database instance
717 717
      */
718
-    public function orderBy($orderBy, $orderDir = ' ASC'){
719
-        if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
718
+    public function orderBy($orderBy, $orderDir = ' ASC') {
719
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
720 720
           $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
721 721
         }
722
-        else{
722
+        else {
723 723
           $this->orderBy = empty($this->orderBy) ? ($orderBy . ' ' 
724 724
                             . strtoupper($orderDir)) : $this->orderBy 
725 725
                             . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -732,11 +732,11 @@  discard block
 block discarded – undo
732 732
      * @param  string|array $field the field name used or array of field list
733 733
      * @return object        the current Database instance
734 734
      */
735
-    public function groupBy($field){
736
-      if (is_array($field)){
735
+    public function groupBy($field) {
736
+      if (is_array($field)) {
737 737
         $this->groupBy = implode(', ', $field);
738 738
       }
739
-      else{
739
+      else {
740 740
         $this->groupBy = $field;
741 741
       }
742 742
       return $this;
@@ -750,13 +750,13 @@  discard block
 block discarded – undo
750 750
      * @param  boolean $escape whether to escape or not the values
751 751
      * @return object        the current Database instance
752 752
      */
753
-    public function having($field, $op = null, $val = null, $escape = true){
754
-      if (is_array($op)){
753
+    public function having($field, $op = null, $val = null, $escape = true) {
754
+      if (is_array($op)) {
755 755
         $x = explode('?', $field);
756 756
         $w = '';
757
-        foreach($x as $k => $v){
758
-  	      if (!empty($v)){
759
-            if (! isset($op[$k])){
757
+        foreach ($x as $k => $v) {
758
+  	      if (!empty($v)) {
759
+            if (!isset($op[$k])) {
760 760
               $op[$k] = '';
761 761
             }
762 762
   	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
@@ -764,14 +764,14 @@  discard block
 block discarded – undo
764 764
       	}
765 765
         $this->having = $w;
766 766
       }
767
-      else if (! in_array($op, $this->operatorList)){
768
-        if (is_null($op)){
767
+      else if (!in_array($op, $this->operatorList)) {
768
+        if (is_null($op)) {
769 769
           $op = '';
770 770
         }
771 771
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
772 772
       }
773
-      else{
774
-        if (is_null($val)){
773
+      else {
774
+        if (is_null($val)) {
775 775
           $val = '';
776 776
         }
777 777
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
      * Return the number of rows returned by the current query
784 784
      * @return int
785 785
      */
786
-    public function numRows(){
786
+    public function numRows() {
787 787
       return $this->numRows;
788 788
     }
789 789
 
@@ -791,15 +791,15 @@  discard block
 block discarded – undo
791 791
      * Return the last insert id value
792 792
      * @return mixed
793 793
      */
794
-    public function insertId(){
794
+    public function insertId() {
795 795
       return $this->insertId;
796 796
     }
797 797
 
798 798
     /**
799 799
      * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
800 800
      */
801
-    public function error(){
802
-  		if ($this->error){
801
+    public function error() {
802
+  		if ($this->error) {
803 803
   			show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
804 804
   		}
805 805
     }
@@ -810,14 +810,14 @@  discard block
 block discarded – undo
810 810
      * If is string will determine the result type "array" or "object"
811 811
      * @return mixed       the query SQL string or the record result
812 812
      */
813
-    public function get($returnSQLQueryOrResultType = false){
813
+    public function get($returnSQLQueryOrResultType = false) {
814 814
       $this->limit = 1;
815 815
       $query = $this->getAll(true);
816
-      if ($returnSQLQueryOrResultType === true){
816
+      if ($returnSQLQueryOrResultType === true) {
817 817
         return $query;
818 818
       }
819
-      else{
820
-        return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) );
819
+      else {
820
+        return $this->query($query, false, (($returnSQLQueryOrResultType == 'array') ? true : false));
821 821
       }
822 822
     }
823 823
 
@@ -827,33 +827,33 @@  discard block
 block discarded – undo
827 827
      * If is string will determine the result type "array" or "object"
828 828
      * @return mixed       the query SQL string or the record result
829 829
      */
830
-    public function getAll($returnSQLQueryOrResultType = false){
830
+    public function getAll($returnSQLQueryOrResultType = false) {
831 831
       $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
832
-      if (! empty($this->join)){
832
+      if (!empty($this->join)) {
833 833
         $query .= $this->join;
834 834
       }
835 835
 	  
836
-      if (! empty($this->where)){
836
+      if (!empty($this->where)) {
837 837
         $query .= ' WHERE ' . $this->where;
838 838
       }
839 839
 
840
-      if (! empty($this->groupBy)){
840
+      if (!empty($this->groupBy)) {
841 841
         $query .= ' GROUP BY ' . $this->groupBy;
842 842
       }
843 843
 
844
-      if (! empty($this->having)){
844
+      if (!empty($this->having)) {
845 845
         $query .= ' HAVING ' . $this->having;
846 846
       }
847 847
 
848
-      if (! empty($this->orderBy)){
848
+      if (!empty($this->orderBy)) {
849 849
           $query .= ' ORDER BY ' . $this->orderBy;
850 850
       }
851 851
 
852
-      if (! empty($this->limit)){
852
+      if (!empty($this->limit)) {
853 853
       	$query .= ' LIMIT ' . $this->limit;
854 854
       }
855 855
 	  
856
-	   if ($returnSQLQueryOrResultType === true){
856
+	   if ($returnSQLQueryOrResultType === true) {
857 857
       	return $query;
858 858
       }
859 859
     	return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
@@ -865,8 +865,8 @@  discard block
 block discarded – undo
865 865
      * @param  boolean $escape  whether to escape or not the values
866 866
      * @return mixed          the insert id of the new record or null
867 867
      */
868
-    public function insert($data = array(), $escape = true){
869
-      if (empty($data) && $this->getData()){
868
+    public function insert($data = array(), $escape = true) {
869
+      if (empty($data) && $this->getData()) {
870 870
         //as when using $this->setData() the data already escaped
871 871
         $escape = false;
872 872
         $data = $this->getData();
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
       $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
880 880
       $query = $this->query($query);
881 881
 
882
-      if ($query){
882
+      if ($query) {
883 883
         $this->insertId = $this->pdo->lastInsertId();
884 884
         return $this->insertId();
885 885
       }
@@ -892,27 +892,27 @@  discard block
 block discarded – undo
892 892
      * @param  boolean $escape  whether to escape or not the values
893 893
      * @return mixed          the update status
894 894
      */
895
-    public function update($data = array(), $escape = true){
895
+    public function update($data = array(), $escape = true) {
896 896
       $query = 'UPDATE ' . $this->from . ' SET ';
897 897
       $values = array();
898
-      if (empty($data) && $this->getData()){
898
+      if (empty($data) && $this->getData()) {
899 899
         //as when using $this->setData() the data already escaped
900 900
         $escape = false;
901 901
         $data = $this->getData();
902 902
       }
903
-      foreach ($data as $column => $val){
903
+      foreach ($data as $column => $val) {
904 904
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
905 905
       }
906 906
       $query .= implode(', ', $values);
907
-      if (! empty($this->where)){
907
+      if (!empty($this->where)) {
908 908
         $query .= ' WHERE ' . $this->where;
909 909
       }
910 910
 
911
-      if (! empty($this->orderBy)){
911
+      if (!empty($this->orderBy)) {
912 912
         $query .= ' ORDER BY ' . $this->orderBy;
913 913
       }
914 914
 
915
-      if (! empty($this->limit)){
915
+      if (!empty($this->limit)) {
916 916
         $query .= ' LIMIT ' . $this->limit;
917 917
       }
918 918
       return $this->query($query);
@@ -922,22 +922,22 @@  discard block
 block discarded – undo
922 922
      * Delete the record in database
923 923
      * @return mixed the delete status
924 924
      */
925
-    public function delete(){
925
+    public function delete() {
926 926
     	$query = 'DELETE FROM ' . $this->from;
927 927
 
928
-    	if (! empty($this->where)){
928
+    	if (!empty($this->where)) {
929 929
     		$query .= ' WHERE ' . $this->where;
930 930
       	}
931 931
 
932
-    	if (! empty($this->orderBy)){
932
+    	if (!empty($this->orderBy)) {
933 933
     	  $query .= ' ORDER BY ' . $this->orderBy;
934 934
       	}
935 935
 
936
-    	if (! empty($this->limit)){
936
+    	if (!empty($this->limit)) {
937 937
     		$query .= ' LIMIT ' . $this->limit;
938 938
       	}
939 939
 
940
-    	if ($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite'){  
940
+    	if ($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite') {  
941 941
     		$query = 'TRUNCATE TABLE ' . $this->from;
942 942
       }
943 943
     	return $this->query($query);
@@ -948,8 +948,8 @@  discard block
 block discarded – undo
948 948
      * @param integer $ttl the cache time to live in second
949 949
      * @return object        the current Database instance
950 950
      */
951
-    public function setCache($ttl = 0){
952
-      if ($ttl > 0){
951
+    public function setCache($ttl = 0) {
952
+      if ($ttl > 0) {
953 953
         $this->cacheTtl = $ttl;
954 954
 		    $this->temporaryCacheTtl = $ttl;
955 955
       }
@@ -961,8 +961,8 @@  discard block
 block discarded – undo
961 961
 	 * @param  integer $ttl the cache time to live in second
962 962
 	 * @return object        the current Database instance
963 963
 	 */
964
-	public function cached($ttl = 0){
965
-      if ($ttl > 0){
964
+	public function cached($ttl = 0) {
965
+      if ($ttl > 0) {
966 966
         $this->temporaryCacheTtl = $ttl;
967 967
       }
968 968
 	  return $this;
@@ -974,9 +974,9 @@  discard block
 block discarded – undo
974 974
      * @param boolean $escaped whether we can do escape of not 
975 975
      * @return mixed       the data after escaped or the same data if not
976 976
      */
977
-    public function escape($data, $escaped = true){
978
-      if ($escaped){
979
-        if (! $this->pdo){
977
+    public function escape($data, $escaped = true) {
978
+      if ($escaped) {
979
+        if (!$this->pdo) {
980 980
           $this->connect();
981 981
         }
982 982
         return $this->pdo->quote(trim($data)); 
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
      * Return the number query executed count for the current request
989 989
      * @return int
990 990
      */
991
-    public function queryCount(){
991
+    public function queryCount() {
992 992
       return $this->queryCount;
993 993
     }
994 994
 
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
      * Return the current query SQL string
997 997
      * @return string
998 998
      */
999
-    public function getQuery(){
999
+    public function getQuery() {
1000 1000
       return $this->query;
1001 1001
     }
1002 1002
 
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
      * Return the application database name
1005 1005
      * @return string
1006 1006
      */
1007
-    public function getDatabaseName(){
1007
+    public function getDatabaseName() {
1008 1008
       return $this->databaseName;
1009 1009
     }
1010 1010
 
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
      * Return the database configuration
1013 1013
      * @return array
1014 1014
      */
1015
-    public  function getDatabaseConfiguration(){
1015
+    public  function getDatabaseConfiguration() {
1016 1016
       return $this->config;
1017 1017
     }
1018 1018
 
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
      * set the database configuration
1021 1021
      * @param array $config the configuration
1022 1022
      */
1023
-    public function setDatabaseConfiguration(array $config){
1023
+    public function setDatabaseConfiguration(array $config) {
1024 1024
       $this->config = array_merge($this->config, $config);
1025 1025
       $this->prefix = $this->config['prefix'];
1026 1026
       $this->databaseName = $this->config['database'];
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
      * Return the PDO instance
1033 1033
      * @return PDO
1034 1034
      */
1035
-    public function getPdo(){
1035
+    public function getPdo() {
1036 1036
       return $this->pdo;
1037 1037
     }
1038 1038
 
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
      * Set the PDO instance
1041 1041
      * @param PDO $pdo the pdo object
1042 1042
      */
1043
-    public function setPdo(PDO $pdo){
1043
+    public function setPdo(PDO $pdo) {
1044 1044
       $this->pdo = $pdo;
1045 1045
       return $this;
1046 1046
     }
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
      * Return the Log instance
1051 1051
      * @return Log
1052 1052
      */
1053
-    public function getLogger(){
1053
+    public function getLogger() {
1054 1054
       return $this->logger;
1055 1055
     }
1056 1056
 
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
      * Set the log instance
1059 1059
      * @param Log $logger the log object
1060 1060
      */
1061
-    public function setLogger($logger){
1061
+    public function setLogger($logger) {
1062 1062
       $this->logger = $logger;
1063 1063
       return $this;
1064 1064
     }
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
      * Return the cache instance
1068 1068
      * @return CacheInterface
1069 1069
      */
1070
-    public function getCacheInstance(){
1070
+    public function getCacheInstance() {
1071 1071
       return $this->cacheInstance;
1072 1072
     }
1073 1073
 
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
      * Set the cache instance
1076 1076
      * @param CacheInterface $cache the cache object
1077 1077
      */
1078
-    public function setCacheInstance($cache){
1078
+    public function setCacheInstance($cache) {
1079 1079
       $this->cacheInstance = $cache;
1080 1080
       return $this;
1081 1081
     }
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
      * Return the benchmark instance
1085 1085
      * @return Benchmark
1086 1086
      */
1087
-    public function getBenchmark(){
1087
+    public function getBenchmark() {
1088 1088
       return $this->benchmarkInstance;
1089 1089
     }
1090 1090
 
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
      * Set the benchmark instance
1093 1093
      * @param Benchmark $cache the cache object
1094 1094
      */
1095
-    public function setBenchmark($benchmark){
1095
+    public function setBenchmark($benchmark) {
1096 1096
       $this->benchmarkInstance = $benchmark;
1097 1097
       return $this;
1098 1098
     }
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
      * Return the data to be used for insert, update, etc.
1102 1102
      * @return array
1103 1103
      */
1104
-    public function getData(){
1104
+    public function getData() {
1105 1105
       return $this->data;
1106 1106
     }
1107 1107
 
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
      * @param boolean $escape whether to escape or not the $value
1113 1113
      * @return object        the current Database instance
1114 1114
      */
1115
-    public function setData($key, $value, $escape = true){
1115
+    public function setData($key, $value, $escape = true) {
1116 1116
       $this->data[$key] = $this->escape($value, $escape);
1117 1117
       return $this;
1118 1118
     }
@@ -1125,14 +1125,14 @@  discard block
 block discarded – undo
1125 1125
      * @param  boolean $array return the result as array
1126 1126
      * @return mixed         the query result
1127 1127
      */
1128
-    public function query($query, $all = true, $array = false){
1128
+    public function query($query, $all = true, $array = false) {
1129 1129
       $this->reset();
1130 1130
       $query = $this->transformPreparedQuery($query, $all);
1131 1131
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
1132 1132
       
1133 1133
       $isSqlSELECTQuery = stristr($this->query, 'SELECT');
1134 1134
 
1135
-      $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . (is_bool($all) && $all ? 'YES':'NO'));
1135
+      $this->logger->info('Execute SQL query [' . $this->query . '], return type: ' . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' . (is_bool($all) && $all ? 'YES' : 'NO'));
1136 1136
       //cache expire time
1137 1137
       $cacheExpire = $this->temporaryCacheTtl;
1138 1138
       
@@ -1148,15 +1148,15 @@  discard block
 block discarded – undo
1148 1148
       //if can use cache feature for this query
1149 1149
       $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
1150 1150
     
1151
-      if ($dbCacheStatus && $isSqlSELECTQuery){
1151
+      if ($dbCacheStatus && $isSqlSELECTQuery) {
1152 1152
           $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
1153 1153
           $cacheContent = $this->getCacheContentForQuery($query, $all, $array);  
1154 1154
       }
1155 1155
       
1156
-      if ( !$cacheContent){
1156
+      if (!$cacheContent) {
1157 1157
         $sqlQuery = $this->runSqlQuery($query, $all, $array);
1158
-        if (is_object($sqlQuery)){
1159
-          if ($isSqlSELECTQuery){
1158
+        if (is_object($sqlQuery)) {
1159
+          if ($isSqlSELECTQuery) {
1160 1160
             $this->setQueryResultForSelect($sqlQuery, $all, $array);
1161 1161
             $this->setCacheContentForQuery(
1162 1162
                                             $this->query, 
@@ -1166,20 +1166,20 @@  discard block
 block discarded – undo
1166 1166
                                             $this->temporaryCacheTtl
1167 1167
                                           );
1168 1168
           }
1169
-          else{
1169
+          else {
1170 1170
               $this->setQueryResultForNonSelect($sqlQuery);
1171
-              if (! $this->result){
1171
+              if (!$this->result) {
1172 1172
                 $this->setQueryError();
1173 1173
               }
1174 1174
           }
1175 1175
         }
1176
-      } else if ($isSqlSELECTQuery){
1177
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
1176
+      } else if ($isSqlSELECTQuery) {
1177
+          $this->logger->info('The result for query [' . $this->query . '] already cached use it');
1178 1178
           $this->result = $cacheContent;
1179 1179
           $this->numRows = count($this->result);
1180 1180
       }
1181 1181
       $this->queryCount++;
1182
-      if (! $this->result){
1182
+      if (!$this->result) {
1183 1183
         $this->logger->info('No result where found for the query [' . $query . ']');
1184 1184
       }
1185 1185
       return $this->result;
@@ -1190,12 +1190,12 @@  discard block
 block discarded – undo
1190 1190
      * Set the Log instance using argument or create new instance
1191 1191
      * @param object $logger the Log instance if not null
1192 1192
      */
1193
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
1194
-      if ($logger !== null){
1193
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
1194
+      if ($logger !== null) {
1195 1195
         $this->logger = $logger;
1196 1196
       }
1197
-      else{
1198
-          $this->logger =& class_loader('Log', 'classes');
1197
+      else {
1198
+          $this->logger = & class_loader('Log', 'classes');
1199 1199
           $this->logger->setLogger('Library::Database');
1200 1200
       }
1201 1201
     }
@@ -1204,14 +1204,14 @@  discard block
 block discarded – undo
1204 1204
     * Setting the database configuration using the configuration file
1205 1205
     * @param array $overwriteConfig the additional configuration to overwrite with the existing one
1206 1206
     */
1207
-    protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()){
1207
+    protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()) {
1208 1208
         $db = array();
1209
-        if (file_exists(CONFIG_PATH . 'database.php')){
1209
+        if (file_exists(CONFIG_PATH . 'database.php')) {
1210 1210
             //here don't use require_once because somewhere user can create database instance directly
1211 1211
             require CONFIG_PATH . 'database.php';
1212 1212
         }
1213 1213
           
1214
-        if (! empty($overwriteConfig)){
1214
+        if (!empty($overwriteConfig)) {
1215 1215
           $db = array_merge($db, $overwriteConfig);
1216 1216
         }
1217 1217
         $config = array(
@@ -1233,9 +1233,9 @@  discard block
 block discarded – undo
1233 1233
      * This method is used to get the PDO DSN string using th configured driver
1234 1234
      * @return string the DSN string
1235 1235
      */
1236
-    protected function getDsnFromDriver(){
1236
+    protected function getDsnFromDriver() {
1237 1237
       $config = $this->getDatabaseConfiguration();
1238
-      if (! empty($config)){
1238
+      if (!empty($config)) {
1239 1239
             $driverDsnMap = array(
1240 1240
                                     'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
1241 1241
                                                 . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') 
@@ -1257,10 +1257,10 @@  discard block
 block discarded – undo
1257 1257
      * Set the database server port configuration using the current hostname like localhost:3309 
1258 1258
      * @return void
1259 1259
      */
1260
-    protected function setPortConfigurationFromHostname(){
1261
-      if (strstr($this->config['hostname'], ':')){
1260
+    protected function setPortConfigurationFromHostname() {
1261
+      if (strstr($this->config['hostname'], ':')) {
1262 1262
         $p = explode(':', $this->config['hostname']);
1263
-        if (count($p) >= 2){
1263
+        if (count($p) >= 2) {
1264 1264
           $this->setDatabaseConfiguration(array(
1265 1265
             'hostname' => $p[0],
1266 1266
             'port' => $p[1]
@@ -1275,15 +1275,15 @@  discard block
 block discarded – undo
1275 1275
      *
1276 1276
      * @return string
1277 1277
      */
1278
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
1278
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
1279 1279
         $_where = array();
1280
-        foreach ($where as $column => $data){
1281
-          if (is_null($data)){
1280
+        foreach ($where as $column => $data) {
1281
+          if (is_null($data)) {
1282 1282
             $data = '';
1283 1283
           }
1284 1284
           $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
1285 1285
         }
1286
-        $where = implode(' '.$andOr.' ', $_where);
1286
+        $where = implode(' ' . $andOr . ' ', $_where);
1287 1287
         return $where;
1288 1288
     }
1289 1289
 
@@ -1293,12 +1293,12 @@  discard block
 block discarded – undo
1293 1293
      *
1294 1294
      * @return string
1295 1295
      */
1296
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
1296
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
1297 1297
        $x = explode('?', $where);
1298 1298
        $w = '';
1299
-        foreach($x as $k => $v){
1300
-          if (! empty($v)){
1301
-              if (isset($op[$k]) && is_null($op[$k])){
1299
+        foreach ($x as $k => $v) {
1300
+          if (!empty($v)) {
1301
+              if (isset($op[$k]) && is_null($op[$k])) {
1302 1302
                 $op[$k] = '';
1303 1303
               }
1304 1304
               $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
@@ -1313,16 +1313,16 @@  discard block
 block discarded – undo
1313 1313
      *
1314 1314
      * @return string
1315 1315
      */
1316
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
1316
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
1317 1317
        $w = '';
1318
-       if (! in_array((string)$op, $this->operatorList)){
1319
-          if (is_null($op)){
1318
+       if (!in_array((string) $op, $this->operatorList)) {
1319
+          if (is_null($op)) {
1320 1320
             $op = '';
1321 1321
           }
1322 1322
           $w = $type . $where . ' = ' . ($this->escape($op, $escape));
1323 1323
         }
1324
-        else{
1325
-          if (is_null($val)){
1324
+        else {
1325
+          if (is_null($val)) {
1326 1326
             $val = '';
1327 1327
           }
1328 1328
           $w = $type . $where . $op . ($this->escape($val, $escape));
@@ -1335,16 +1335,16 @@  discard block
 block discarded – undo
1335 1335
        * @param string $whereStr the WHERE clause string
1336 1336
        * @param  string  $andOr the separator type used 'AND', 'OR', etc.
1337 1337
        */
1338
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
1339
-        if (empty($this->where)){
1338
+      protected function setWhereStr($whereStr, $andOr = 'AND') {
1339
+        if (empty($this->where)) {
1340 1340
           $this->where = $whereStr;
1341 1341
         }
1342
-        else{
1343
-          if (substr($this->where, -1) == '('){
1342
+        else {
1343
+          if (substr($this->where, -1) == '(') {
1344 1344
             $this->where = $this->where . ' ' . $whereStr;
1345 1345
           }
1346
-          else{
1347
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
1346
+          else {
1347
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
1348 1348
           }
1349 1349
         }
1350 1350
       }
@@ -1355,12 +1355,12 @@  discard block
 block discarded – undo
1355 1355
      *
1356 1356
      * @return string
1357 1357
      */
1358
-    protected function transformPreparedQuery($query, $data){
1359
-      if (is_array($data)){
1358
+    protected function transformPreparedQuery($query, $data) {
1359
+      if (is_array($data)) {
1360 1360
         $x = explode('?', $query);
1361 1361
         $q = '';
1362
-        foreach($x as $k => $v){
1363
-          if (! empty($v)){
1362
+        foreach ($x as $k => $v) {
1363
+          if (!empty($v)) {
1364 1364
             $q .= $v . (isset($data[$k]) ? $this->escape($data[$k]) : '');
1365 1365
           }
1366 1366
         }
@@ -1375,8 +1375,8 @@  discard block
 block discarded – undo
1375 1375
      * 
1376 1376
      *  @return string
1377 1377
      */
1378
-    protected function getCacheBenchmarkKeyForQuery($query, $all, $array){
1379
-      if (is_array($all)){
1378
+    protected function getCacheBenchmarkKeyForQuery($query, $all, $array) {
1379
+      if (is_array($all)) {
1380 1380
         $all = 'array';
1381 1381
       }
1382 1382
       return md5($query . $all . $array);
@@ -1388,9 +1388,9 @@  discard block
 block discarded – undo
1388 1388
      *      
1389 1389
      * @return mixed
1390 1390
      */
1391
-    protected function getCacheContentForQuery($query, $all, $array){
1391
+    protected function getCacheContentForQuery($query, $all, $array) {
1392 1392
         $cacheKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
1393
-        if (is_object($this->cacheInstance)){
1393
+        if (is_object($this->cacheInstance)) {
1394 1394
           return $this->cacheInstance->get($cacheKey);
1395 1395
         }
1396 1396
         $instance = & get_instance()->cache;
@@ -1406,9 +1406,9 @@  discard block
 block discarded – undo
1406 1406
      * @param boolean $status whether can save the query result into cache
1407 1407
      * @param int $expire the cache TTL
1408 1408
      */
1409
-     protected function setCacheContentForQuery($query, $key, $result, $status, $expire){
1410
-        if ($status){
1411
-            $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
1409
+     protected function setCacheContentForQuery($query, $key, $result, $status, $expire) {
1410
+        if ($status) {
1411
+            $this->logger->info('Save the result for query [' . $query . '] into cache for future use');
1412 1412
             $this->getCacheInstance()->set($key, $result, $expire);
1413 1413
         }
1414 1414
      }
@@ -1417,19 +1417,19 @@  discard block
 block discarded – undo
1417 1417
      * Set the result for SELECT query using PDOStatment
1418 1418
      * @see Database::query
1419 1419
      */
1420
-    protected function setQueryResultForSelect($pdoStatment, $all, $array){
1420
+    protected function setQueryResultForSelect($pdoStatment, $all, $array) {
1421 1421
       //if need return all result like list of record
1422
-      if (is_bool($all) && $all){
1422
+      if (is_bool($all) && $all) {
1423 1423
           $this->result = ($array === false) ? $pdoStatment->fetchAll(PDO::FETCH_OBJ) : $pdoStatment->fetchAll(PDO::FETCH_ASSOC);
1424 1424
       }
1425
-      else{
1425
+      else {
1426 1426
           $this->result = ($array === false) ? $pdoStatment->fetch(PDO::FETCH_OBJ) : $pdoStatment->fetch(PDO::FETCH_ASSOC);
1427 1427
       }
1428 1428
       //Sqlite and pgsql always return 0 when using rowCount()
1429
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1429
+      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1430 1430
         $this->numRows = count($this->result);  
1431 1431
       }
1432
-      else{
1432
+      else {
1433 1433
         $this->numRows = $pdoStatment->rowCount(); 
1434 1434
       }
1435 1435
     }
@@ -1438,13 +1438,13 @@  discard block
 block discarded – undo
1438 1438
      * Set the result for other command than SELECT query using PDOStatment
1439 1439
      * @see Database::query
1440 1440
      */
1441
-    protected function setQueryResultForNonSelect($pdoStatment){
1441
+    protected function setQueryResultForNonSelect($pdoStatment) {
1442 1442
       //Sqlite and pgsql always return 0 when using rowCount()
1443
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1443
+      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1444 1444
         $this->result = 1; //to test the result for the query like UPDATE, INSERT, DELETE
1445 1445
         $this->numRows = 1;  
1446 1446
       }
1447
-      else{
1447
+      else {
1448 1448
           $this->result = $pdoStatment->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
1449 1449
           $this->numRows = $pdoStatment->rowCount(); 
1450 1450
       }
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
     /**
1454 1454
      * Set error for database query execution
1455 1455
      */
1456
-    protected function setQueryError(){
1456
+    protected function setQueryError() {
1457 1457
       $error = $this->pdo->errorInfo();
1458 1458
       $this->error = isset($error[2]) ? $error[2] : '';
1459 1459
       $this->logger->error('The database query execution got error: ' . stringfy_vars($error));
@@ -1466,16 +1466,16 @@  discard block
 block discarded – undo
1466 1466
      * 
1467 1467
      * @return object|void
1468 1468
      */
1469
-    protected function runSqlQuery($query, $all, $array){
1469
+    protected function runSqlQuery($query, $all, $array) {
1470 1470
        //for database query execution time
1471 1471
         $benchmarkMarkerKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
1472 1472
         $benchmarkInstance = $this->getBenchmark();
1473
-        if (! is_object($benchmarkInstance)){
1473
+        if (!is_object($benchmarkInstance)) {
1474 1474
           $obj = & get_instance();
1475 1475
           $benchmarkInstance = $obj->benchmark; 
1476 1476
           $this->setBenchmark($benchmarkInstance);
1477 1477
         }
1478
-        if (! $this->pdo){
1478
+        if (!$this->pdo) {
1479 1479
             $this->connect();
1480 1480
         }
1481 1481
         
@@ -1486,10 +1486,10 @@  discard block
 block discarded – undo
1486 1486
         //get response time for this query
1487 1487
         $responseTime = $benchmarkInstance->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
1488 1488
         //TODO use the configuration value for the high response time currently is 1 second
1489
-        if ($responseTime >= 1 ){
1490
-            $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
1489
+        if ($responseTime >= 1) {
1490
+            $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.');
1491 1491
         }
1492
-        if ($sqlQuery){
1492
+        if ($sqlQuery) {
1493 1493
           return $sqlQuery;
1494 1494
         }
1495 1495
         $this->setQueryError();
@@ -1498,7 +1498,7 @@  discard block
 block discarded – undo
1498 1498
     /**
1499 1499
      * Reset the database class attributs to the initail values before each query.
1500 1500
      */
1501
-    private function reset(){
1501
+    private function reset() {
1502 1502
       $this->select   = '*';
1503 1503
       $this->from     = null;
1504 1504
       $this->where    = null;
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
     /**
1519 1519
      * The class destructor
1520 1520
      */
1521
-    public function __destruct(){
1521
+    public function __destruct() {
1522 1522
       $this->pdo = null;
1523 1523
   }
1524 1524
 
Please login to merge, or discard this patch.