Passed
Push — master ( 5caf99...fc77ff )
by Maike
01:57
created
lib/Model.php 1 patch
Braces   +75 added lines, -27 removed lines patch added patch discarded remove patch
@@ -68,7 +68,9 @@  discard block
 block discarded – undo
68 68
             }
69 69
 
70 70
             if (!is_null($array)) {
71
-                if (!is_array($array)) throw new \InvalidArgumentException('Accept only array from object');
71
+                if (!is_array($array)) {
72
+                 throw new \InvalidArgumentException('Accept only array from object');
73
+                }
72 74
 
73 75
                 $this->_data = $array;
74 76
                 $this->_newData = $array;
@@ -102,9 +104,13 @@  discard block
 block discarded – undo
102 104
      */
103 105
     public function __get($name)
104 106
     {
105
-        if (strtolower($name) == 'errors') return Error::instance();
107
+        if (strtolower($name) == 'errors') {
108
+         return Error::instance();
109
+        }
106 110
 
107
-        if (!key_exists($name, $this->_data)) throw new \Exception("The attribute $name not found.");
111
+        if (!key_exists($name, $this->_data)) {
112
+         throw new \Exception("The attribute $name not found.");
113
+        }
108 114
 
109 115
         return $this->_data[$name];
110 116
     }
@@ -207,14 +213,18 @@  discard block
 block discarded – undo
207 213
             $sql .= " ($repeat); ";
208 214
         }
209 215
 
210
-        if (is_callable($this->triggerBefore)) ($this->triggerBefore)();
216
+        if (is_callable($this->triggerBefore)) {
217
+         ($this->triggerBefore)();
218
+        }
211 219
 
212 220
         $start = microtime(true);
213 221
         $insert = $this->Connection->getConnection()->prepare($sql);
214 222
         $this->burnError($insert);
215 223
 
216 224
         $this->_newData = array_map(function ($data) {
217
-            if (is_bool($data) and $data === false) $data = 0;
225
+            if (is_bool($data) and $data === false) {
226
+             $data = 0;
227
+            }
218 228
 
219 229
             return $data;
220 230
         }, $this->_newData);
@@ -225,7 +235,9 @@  discard block
 block discarded – undo
225 235
 
226 236
         $this->Connection->setPerformedQuery($insert->queryString, round(($end - $start), 5));
227 237
 
228
-        if (is_callable($this->triggerAfter)) ($this->triggerAfter)();
238
+        if (is_callable($this->triggerAfter)) {
239
+         ($this->triggerAfter)();
240
+        }
229 241
 
230 242
         if ($update) {
231 243
             $this->burnError($insert);
@@ -264,7 +276,9 @@  discard block
 block discarded – undo
264 276
 
265 277
     private function burnError($statment)
266 278
     {
267
-        if (!is_null($statment->errorInfo()[1])) throw new \Exception($statment->errorInfo()[2], $statment->errorInfo()[1]);
279
+        if (!is_null($statment->errorInfo()[1])) {
280
+         throw new \Exception($statment->errorInfo()[2], $statment->errorInfo()[1]);
281
+        }
268 282
     }
269 283
 
270 284
     /**
@@ -279,16 +293,23 @@  discard block
 block discarded – undo
279 293
             throw new \Exception($e->getMessage());
280 294
         }
281 295
 
282
-        if (!isset(static::$primary_key)) throw new \Exception('Primary key don\'t set');
296
+        if (!isset(static::$primary_key)) {
297
+         throw new \Exception('Primary key don\'t set');
298
+        }
283 299
 
284
-        if (!is_numeric($this->{static::$primary_key})) throw new \Exception('Primary key value don\'t is valid');
300
+        if (!is_numeric($this->{static::$primary_key})) {
301
+         throw new \Exception('Primary key value don\'t is valid');
302
+        }
285 303
 
286 304
         $sql = ' DELETE FROM ' . static::$table_name;
287 305
         $sql .= ' WHERE ' . static::$primary_key . ' = ? ';
288 306
 
289 307
         $instance = self::$_instance;
290 308
 
291
-        if (is_callable($this->triggerBefore)) ($this->triggerBefore)();;
309
+        if (is_callable($this->triggerBefore)) {
310
+         ($this->triggerBefore)();
311
+        }
312
+        ;
292 313
 
293 314
         $start = microtime(true);
294 315
 
@@ -299,7 +320,9 @@  discard block
 block discarded – undo
299 320
 
300 321
         $instance->Connection->setPerformedQuery($insert->queryString, round(($end - $start), 5));
301 322
 
302
-        if (is_callable($this->triggerAfter)) ($this->triggerAfter)();
323
+        if (is_callable($this->triggerAfter)) {
324
+         ($this->triggerAfter)();
325
+        }
303 326
 
304 327
         if ($insert->rowCount() > 0) {
305 328
             $logger = [
@@ -310,8 +333,7 @@  discard block
 block discarded – undo
310 333
             $this->saveLogger($logger);
311 334
 
312 335
             return true;
313
-        }
314
-        else{ return false; };
336
+        } else{ return false; };
315 337
     }
316 338
 
317 339
     /**
@@ -331,7 +353,9 @@  discard block
 block discarded – undo
331 353
     {
332 354
         self::instance();
333 355
 
334
-        if (!isset(static::$table_name)) throw new \Exception('Don\'t set table name in model.');
356
+        if (!isset(static::$table_name)) {
357
+         throw new \Exception('Don\'t set table name in model.');
358
+        }
335 359
 
336 360
         $currentTable = static::$table_name;
337 361
 
@@ -359,8 +383,12 @@  discard block
 block discarded – undo
359 383
     {
360 384
         self::instance();
361 385
 
362
-        if (!is_string($procedureName)) throw new \Exception("Procedure name is invalid.");
363
-        if (!is_array($param)) throw new \Exception("Tipo de parâmetros inválidos.");
386
+        if (!is_string($procedureName)) {
387
+         throw new \Exception("Procedure name is invalid.");
388
+        }
389
+        if (!is_array($param)) {
390
+         throw new \Exception("Tipo de parâmetros inválidos.");
391
+        }
364 392
 
365 393
         $currentTable = static::$table_name;
366 394
 
@@ -435,13 +463,17 @@  discard block
 block discarded – undo
435 463
             throw new \Exception($e->getMessage());
436 464
         }
437 465
 
438
-        if (!is_array($parameters) and !is_numeric($parameters)) throw new \Exception('Invalid parameter type on model ' . get_called_class() . '.');
466
+        if (!is_array($parameters) and !is_numeric($parameters)) {
467
+         throw new \Exception('Invalid parameter type on model ' . get_called_class() . '.');
468
+        }
439 469
 
440 470
         $instance->_current_custom_query[] = 'SELECT * FROM ' . static::$table_name . ' ';
441 471
 
442 472
         switch ($parameters) {
443 473
             case is_numeric($parameters):
444
-                if (!isset(static::$primary_key)) throw new \Exception("Invalid parameter type.");
474
+                if (!isset(static::$primary_key)) {
475
+                 throw new \Exception("Invalid parameter type.");
476
+                }
445 477
 
446 478
                 $instance->_current_custom_query_values[] = $parameters;
447 479
                 $instance->_current_custom_query[] = ' WHERE ' . static::$primary_key . ' = ?';
@@ -464,7 +496,7 @@  discard block
 block discarded – undo
464 496
             $done->Result->setResults($clone);
465 497
 
466 498
             return $done;
467
-        }else {
499
+        } else {
468 500
             return null;
469 501
         }
470 502
     }
@@ -485,11 +517,15 @@  discard block
 block discarded – undo
485 517
             throw new \Exception($e->getMessage());
486 518
         }
487 519
 
488
-        if (!is_string($colunm)) throw new \Exception("Invalid parameter type.");
520
+        if (!is_string($colunm)) {
521
+         throw new \Exception("Invalid parameter type.");
522
+        }
489 523
 
490 524
         self::$_instance->_current_custom_query[] = "SELECT $colunm FROM " . static::$table_name . ' ';
491 525
 
492
-        if (!isset(static::$primary_key)) throw new \Exception("Invalid parameter type.");
526
+        if (!isset(static::$primary_key)) {
527
+         throw new \Exception("Invalid parameter type.");
528
+        }
493 529
 
494 530
         return self::$_instance;
495 531
     }
@@ -539,7 +575,9 @@  discard block
 block discarded – undo
539 575
             throw new \Exception($e->getMessage());
540 576
         }
541 577
 
542
-        if (!is_array($param)) throw new \Exception('Tipo de parâmetro inválido.');
578
+        if (!is_array($param)) {
579
+         throw new \Exception('Tipo de parâmetro inválido.');
580
+        }
543 581
 
544 582
         $start = microtime(true);
545 583
 
@@ -584,7 +622,9 @@  discard block
 block discarded – undo
584 622
             throw new \Exception($e->getMessage());
585 623
         }
586 624
 
587
-        if (!is_array($param)) throw new \Exception('Invalid parameter type.');
625
+        if (!is_array($param)) {
626
+         throw new \Exception('Invalid parameter type.');
627
+        }
588 628
 
589 629
         self::$_instance->_current_custom_query_values = $param;
590 630
 
@@ -623,7 +663,9 @@  discard block
 block discarded – undo
623 663
      */
624 664
     final protected function setTriggerAfter($closure = null)
625 665
     {
626
-        if (!is_callable($closure)) throw new \Exception('The parameter don\'t is an closure.');
666
+        if (!is_callable($closure)) {
667
+         throw new \Exception('The parameter don\'t is an closure.');
668
+        }
627 669
 
628 670
         $this->triggerAfter = $closure;
629 671
 
@@ -638,7 +680,9 @@  discard block
 block discarded – undo
638 680
      */
639 681
     final protected function setTriggerBefore($closure = null)
640 682
     {
641
-        if (!is_callable($closure)) throw new \Exception('The parameter don\'t is an closure.');
683
+        if (!is_callable($closure)) {
684
+         throw new \Exception('The parameter don\'t is an closure.');
685
+        }
642 686
 
643 687
         $this->triggerBefore = $closure;
644 688
 
@@ -652,7 +696,9 @@  discard block
 block discarded – undo
652 696
      */
653 697
     final protected function changeSchema($schema)
654 698
     {
655
-        if (!is_string($schema)) throw new \Exception('The parameter don\'t is an String.');
699
+        if (!is_string($schema)) {
700
+         throw new \Exception('The parameter don\'t is an String.');
701
+        }
656 702
 
657 703
         $this->Connection->changeSchema($schema);
658 704
         return $this;
@@ -691,7 +737,9 @@  discard block
 block discarded – undo
691 737
      */
692 738
     final private function verifyConnection()
693 739
     {
694
-        if (is_null($this->Connection->getCurrentConnectionString())) throw new \Exception('Not set connection.');
740
+        if (is_null($this->Connection->getCurrentConnectionString())) {
741
+         throw new \Exception('Not set connection.');
742
+        }
695 743
     }
696 744
 
697 745
     /**
Please login to merge, or discard this patch.