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