@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | 'password' => $this->_password[$connectionName], |
150 | 150 | 'charset' => $this->_charset[$connectionName], |
151 | 151 | 'schema' => $this->_schema[$connectionName]]; |
152 | - } else { |
|
152 | + }else { |
|
153 | 153 | throw new \Exception("The connection name $connectionName is not set."); |
154 | 154 | } |
155 | 155 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | |
184 | 184 | $connectionSettings = (object)$connectionSettings; |
185 | 185 | |
186 | - $this->_connectionString[$connectionName] = $this->_driver[$connectionName].":host=$connectionSettings->host;dbname=$connectionSettings->database;port=$connectionSettings->port;"; |
|
186 | + $this->_connectionString[$connectionName] = $this->_driver[$connectionName] . ":host=$connectionSettings->host;dbname=$connectionSettings->database;port=$connectionSettings->port;"; |
|
187 | 187 | |
188 | 188 | return $this; |
189 | 189 | } |
@@ -79,15 +79,27 @@ discard block |
||
79 | 79 | $defaultSchema = null) |
80 | 80 | { |
81 | 81 | #Begin: Verify if all parameters send is valid. |
82 | - if (!is_string($driver) || !in_array($driver, self::DRIVERS)) throw new \Exception("The driver $driver don't supported."); |
|
83 | - if (!is_string($username) || empty($username)) throw new \Exception("Invalid username."); |
|
84 | - if (!is_string($password) || empty($password)) throw new \Exception("Invalid password."); |
|
85 | - if (!is_string($host) || empty($host)) throw new \Exception("Invalid host."); |
|
86 | - if (!is_string($database) || empty($database)) throw new \Exception("Invalid database name."); |
|
82 | + if (!is_string($driver) || !in_array($driver, self::DRIVERS)) { |
|
83 | + throw new \Exception("The driver $driver don't supported."); |
|
84 | + } |
|
85 | + if (!is_string($username) || empty($username)) { |
|
86 | + throw new \Exception("Invalid username."); |
|
87 | + } |
|
88 | + if (!is_string($password) || empty($password)) { |
|
89 | + throw new \Exception("Invalid password."); |
|
90 | + } |
|
91 | + if (!is_string($host) || empty($host)) { |
|
92 | + throw new \Exception("Invalid host."); |
|
93 | + } |
|
94 | + if (!is_string($database) || empty($database)) { |
|
95 | + throw new \Exception("Invalid database name."); |
|
96 | + } |
|
87 | 97 | $this->validatesConnectionName($connectionName); |
88 | 98 | |
89 | 99 | $port = is_null($port) ? '' : (int)$port; |
90 | - if (!is_null($port) && !is_int($port)) throw new \Exception("Invalid port format."); |
|
100 | + if (!is_null($port) && !is_int($port)) { |
|
101 | + throw new \Exception("Invalid port format."); |
|
102 | + } |
|
91 | 103 | #Constructor of the connection string |
92 | 104 | $this->_connectionString[$connectionName] = "$driver:host=$host;dbname=$database;port=$port;"; |
93 | 105 | $this->_username[$connectionName] = $username; |
@@ -176,8 +188,12 @@ discard block |
||
176 | 188 | */ |
177 | 189 | public function setSettings($connectionName, $connectionSettings) |
178 | 190 | { |
179 | - if (!is_array($connectionSettings)) throw new \Exception('Invalid format connectionSettings'); |
|
180 | - if (empty($this->_driver[$connectionName])) throw new \Exception('Driver not set.'); |
|
191 | + if (!is_array($connectionSettings)) { |
|
192 | + throw new \Exception('Invalid format connectionSettings'); |
|
193 | + } |
|
194 | + if (empty($this->_driver[$connectionName])) { |
|
195 | + throw new \Exception('Driver not set.'); |
|
196 | + } |
|
181 | 197 | |
182 | 198 | $this->validatesConnectionName($connectionName); |
183 | 199 |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $this->Result = new Result(); |
76 | 76 | |
77 | - if($this->Result && !$this->Result->getResults()) { |
|
77 | + if ($this->Result && !$this->Result->getResults()) { |
|
78 | 78 | $clone = clone $this; |
79 | 79 | $this->Result->setResults($clone); |
80 | 80 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $this->_newData[] = $this->{$key}; |
189 | 189 | |
190 | 190 | $update = true; |
191 | - } else { |
|
191 | + }else { |
|
192 | 192 | $logger = [ |
193 | 193 | 'function' => 'Save', |
194 | 194 | 'next' => $this->_data, |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $insert = $this->Connection->getConnection()->prepare($sql); |
213 | 213 | $this->burnError($insert); |
214 | 214 | |
215 | - $this->_newData = array_map(function ($data) { |
|
215 | + $this->_newData = array_map(function($data) { |
|
216 | 216 | if (is_bool($data) and $data === false) $data = 0; |
217 | 217 | |
218 | 218 | return $data; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | $instance = self::$_instance; |
289 | 289 | |
290 | - if (is_callable($this->triggerBefore)) ($this->triggerBefore)();; |
|
290 | + if (is_callable($this->triggerBefore)) ($this->triggerBefore)(); ; |
|
291 | 291 | |
292 | 292 | $start = microtime(true); |
293 | 293 | |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | |
311 | 311 | return true; |
312 | 312 | } |
313 | - else{ return false; }; |
|
313 | + else { return false; }; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | |
456 | 456 | $done = $instance->done(); |
457 | 457 | |
458 | - if(count($done) > 0) { |
|
458 | + if (count($done) > 0) { |
|
459 | 459 | $done = $done[0]; |
460 | 460 | |
461 | 461 | $clone = clone $done; |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | |
558 | 558 | if ($match) { |
559 | 559 | $this->_data = $objetos = $consulta->fetchAll(\PDO::FETCH_CLASS, get_called_class()); |
560 | - } else { |
|
560 | + }else { |
|
561 | 561 | $objetos = $consulta->rowCount(); |
562 | 562 | } |
563 | 563 |
@@ -66,7 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | if (!is_null($object)) { |
69 | - if (!is_array($object)) throw new \InvalidArgumentException('Accept only array from object'); |
|
69 | + if (!is_array($object)) { |
|
70 | + throw new \InvalidArgumentException('Accept only array from object'); |
|
71 | + } |
|
70 | 72 | |
71 | 73 | $this->_data = $object; |
72 | 74 | $this->_newData = $object; |
@@ -100,9 +102,13 @@ discard block |
||
100 | 102 | */ |
101 | 103 | public function __get($name) |
102 | 104 | { |
103 | - if (strtolower($name) == 'errors') return Error::instance(); |
|
105 | + if (strtolower($name) == 'errors') { |
|
106 | + return Error::instance(); |
|
107 | + } |
|
104 | 108 | |
105 | - if (!key_exists($name, $this->_data)) throw new \Exception("The attribute $name not found."); |
|
109 | + if (!key_exists($name, $this->_data)) { |
|
110 | + throw new \Exception("The attribute $name not found."); |
|
111 | + } |
|
106 | 112 | |
107 | 113 | return $this->_data[$name]; |
108 | 114 | } |
@@ -206,14 +212,18 @@ discard block |
||
206 | 212 | } |
207 | 213 | |
208 | 214 | |
209 | - if (is_callable($this->triggerBefore)) ($this->triggerBefore)(); |
|
215 | + if (is_callable($this->triggerBefore)) { |
|
216 | + ($this->triggerBefore)(); |
|
217 | + } |
|
210 | 218 | |
211 | 219 | $start = microtime(true); |
212 | 220 | $insert = $this->Connection->getConnection()->prepare($sql); |
213 | 221 | $this->burnError($insert); |
214 | 222 | |
215 | 223 | $this->_newData = array_map(function ($data) { |
216 | - if (is_bool($data) and $data === false) $data = 0; |
|
224 | + if (is_bool($data) and $data === false) { |
|
225 | + $data = 0; |
|
226 | + } |
|
217 | 227 | |
218 | 228 | return $data; |
219 | 229 | }, $this->_newData); |
@@ -224,7 +234,9 @@ discard block |
||
224 | 234 | |
225 | 235 | $this->Connection->setPerformedQuery($insert->queryString, round(($end - $start), 5)); |
226 | 236 | |
227 | - if (is_callable($this->triggerAfter)) ($this->triggerAfter)(); |
|
237 | + if (is_callable($this->triggerAfter)) { |
|
238 | + ($this->triggerAfter)(); |
|
239 | + } |
|
228 | 240 | |
229 | 241 | if ($update) { |
230 | 242 | $this->burnError($insert); |
@@ -263,7 +275,9 @@ discard block |
||
263 | 275 | |
264 | 276 | private function burnError($statment) |
265 | 277 | { |
266 | - if (!is_null($statment->errorInfo()[1])) throw new \Exception($statment->errorInfo()[2], $statment->errorInfo()[1]); |
|
278 | + if (!is_null($statment->errorInfo()[1])) { |
|
279 | + throw new \Exception($statment->errorInfo()[2], $statment->errorInfo()[1]); |
|
280 | + } |
|
267 | 281 | } |
268 | 282 | |
269 | 283 | /** |
@@ -278,16 +292,23 @@ discard block |
||
278 | 292 | throw new \Exception($e->getMessage()); |
279 | 293 | } |
280 | 294 | |
281 | - if (!isset(static::$primary_key)) throw new \Exception('Primary key don\'t set'); |
|
295 | + if (!isset(static::$primary_key)) { |
|
296 | + throw new \Exception('Primary key don\'t set'); |
|
297 | + } |
|
282 | 298 | |
283 | - if (!is_numeric($this->{static::$primary_key})) throw new \Exception('Primary key value don\'t is valid'); |
|
299 | + if (!is_numeric($this->{static::$primary_key})) { |
|
300 | + throw new \Exception('Primary key value don\'t is valid'); |
|
301 | + } |
|
284 | 302 | |
285 | 303 | $sql = ' DELETE FROM ' . static::$table_name; |
286 | 304 | $sql .= ' WHERE ' . static::$primary_key . ' = ? '; |
287 | 305 | |
288 | 306 | $instance = self::$_instance; |
289 | 307 | |
290 | - if (is_callable($this->triggerBefore)) ($this->triggerBefore)();; |
|
308 | + if (is_callable($this->triggerBefore)) { |
|
309 | + ($this->triggerBefore)(); |
|
310 | + } |
|
311 | + ; |
|
291 | 312 | |
292 | 313 | $start = microtime(true); |
293 | 314 | |
@@ -298,7 +319,9 @@ discard block |
||
298 | 319 | |
299 | 320 | $instance->Connection->setPerformedQuery($insert->queryString, round(($end - $start), 5)); |
300 | 321 | |
301 | - if (is_callable($this->triggerAfter)) ($this->triggerAfter)(); |
|
322 | + if (is_callable($this->triggerAfter)) { |
|
323 | + ($this->triggerAfter)(); |
|
324 | + } |
|
302 | 325 | |
303 | 326 | if ($insert->rowCount() > 0) { |
304 | 327 | $logger = [ |
@@ -309,8 +332,7 @@ discard block |
||
309 | 332 | $this->saveLogger($logger); |
310 | 333 | |
311 | 334 | return true; |
312 | - } |
|
313 | - else{ return false; }; |
|
335 | + } else{ return false; }; |
|
314 | 336 | } |
315 | 337 | |
316 | 338 | /** |
@@ -330,7 +352,9 @@ discard block |
||
330 | 352 | { |
331 | 353 | self::instance(); |
332 | 354 | |
333 | - if (!isset(static::$table_name)) throw new \Exception('Don\'t set table name in model.'); |
|
355 | + if (!isset(static::$table_name)) { |
|
356 | + throw new \Exception('Don\'t set table name in model.'); |
|
357 | + } |
|
334 | 358 | |
335 | 359 | $currentTable = static::$table_name; |
336 | 360 | |
@@ -358,8 +382,12 @@ discard block |
||
358 | 382 | { |
359 | 383 | self::instance(); |
360 | 384 | |
361 | - if (!is_string($procedureName)) throw new \Exception("Procedure name is invalid."); |
|
362 | - if (!is_array($param)) throw new \Exception("Tipo de parâmetros inválidos."); |
|
385 | + if (!is_string($procedureName)) { |
|
386 | + throw new \Exception("Procedure name is invalid."); |
|
387 | + } |
|
388 | + if (!is_array($param)) { |
|
389 | + throw new \Exception("Tipo de parâmetros inválidos."); |
|
390 | + } |
|
363 | 391 | |
364 | 392 | $currentTable = static::$table_name; |
365 | 393 | |
@@ -434,13 +462,17 @@ discard block |
||
434 | 462 | throw new \Exception($e->getMessage()); |
435 | 463 | } |
436 | 464 | |
437 | - if (!is_array($parameters) and !is_numeric($parameters)) throw new \Exception('Invalid parameter type on model ' . get_called_class() . '.'); |
|
465 | + if (!is_array($parameters) and !is_numeric($parameters)) { |
|
466 | + throw new \Exception('Invalid parameter type on model ' . get_called_class() . '.'); |
|
467 | + } |
|
438 | 468 | |
439 | 469 | $instance->_current_custom_query[] = 'SELECT * FROM ' . static::$table_name . ' '; |
440 | 470 | |
441 | 471 | switch ($parameters) { |
442 | 472 | case is_numeric($parameters): |
443 | - if (!isset(static::$primary_key)) throw new \Exception("Invalid parameter type."); |
|
473 | + if (!isset(static::$primary_key)) { |
|
474 | + throw new \Exception("Invalid parameter type."); |
|
475 | + } |
|
444 | 476 | |
445 | 477 | $instance->_current_custom_query_values[] = $parameters; |
446 | 478 | $instance->_current_custom_query[] = ' WHERE ' . static::$primary_key . ' = ?'; |
@@ -463,7 +495,7 @@ discard block |
||
463 | 495 | $done->Result->setResults($clone); |
464 | 496 | |
465 | 497 | return $done; |
466 | - }else { |
|
498 | + } else { |
|
467 | 499 | return null; |
468 | 500 | } |
469 | 501 | } |
@@ -484,11 +516,15 @@ discard block |
||
484 | 516 | throw new \Exception($e->getMessage()); |
485 | 517 | } |
486 | 518 | |
487 | - if (!is_string($colunm)) throw new \Exception("Invalid parameter type."); |
|
519 | + if (!is_string($colunm)) { |
|
520 | + throw new \Exception("Invalid parameter type."); |
|
521 | + } |
|
488 | 522 | |
489 | 523 | self::$_instance->_current_custom_query[] = "SELECT $colunm FROM " . static::$table_name . ' '; |
490 | 524 | |
491 | - if (!isset(static::$primary_key)) throw new \Exception("Invalid parameter type."); |
|
525 | + if (!isset(static::$primary_key)) { |
|
526 | + throw new \Exception("Invalid parameter type."); |
|
527 | + } |
|
492 | 528 | |
493 | 529 | return self::$_instance; |
494 | 530 | } |
@@ -538,7 +574,9 @@ discard block |
||
538 | 574 | throw new \Exception($e->getMessage()); |
539 | 575 | } |
540 | 576 | |
541 | - if (!is_array($param)) throw new \Exception('Tipo de parâmetro inválido.'); |
|
577 | + if (!is_array($param)) { |
|
578 | + throw new \Exception('Tipo de parâmetro inválido.'); |
|
579 | + } |
|
542 | 580 | |
543 | 581 | $start = microtime(true); |
544 | 582 | |
@@ -583,7 +621,9 @@ discard block |
||
583 | 621 | throw new \Exception($e->getMessage()); |
584 | 622 | } |
585 | 623 | |
586 | - if (!is_array($param)) throw new \Exception('Invalid parameter type.'); |
|
624 | + if (!is_array($param)) { |
|
625 | + throw new \Exception('Invalid parameter type.'); |
|
626 | + } |
|
587 | 627 | |
588 | 628 | self::$_instance->_current_custom_query_values = $param; |
589 | 629 | |
@@ -622,7 +662,9 @@ discard block |
||
622 | 662 | */ |
623 | 663 | final protected function setTriggerAfter($closure = null) |
624 | 664 | { |
625 | - if (!is_callable($closure)) throw new Exception('The parameter don\'t is an closure.'); |
|
665 | + if (!is_callable($closure)) { |
|
666 | + throw new Exception('The parameter don\'t is an closure.'); |
|
667 | + } |
|
626 | 668 | |
627 | 669 | $this->triggerAfter = $closure; |
628 | 670 | |
@@ -637,7 +679,9 @@ discard block |
||
637 | 679 | */ |
638 | 680 | final protected function setTriggerBefore($closure = null) |
639 | 681 | { |
640 | - if (!is_callable($closure)) throw new Exception('The parameter don\'t is an closure.'); |
|
682 | + if (!is_callable($closure)) { |
|
683 | + throw new Exception('The parameter don\'t is an closure.'); |
|
684 | + } |
|
641 | 685 | |
642 | 686 | $this->triggerBefore = $closure; |
643 | 687 | |
@@ -651,7 +695,9 @@ discard block |
||
651 | 695 | */ |
652 | 696 | final protected function changeSchema($schema) |
653 | 697 | { |
654 | - if (!is_string($schema)) throw new \Exception('The parameter don\'t is an String.'); |
|
698 | + if (!is_string($schema)) { |
|
699 | + throw new \Exception('The parameter don\'t is an String.'); |
|
700 | + } |
|
655 | 701 | |
656 | 702 | $this->Connection->changeSchema($schema); |
657 | 703 | return $this; |
@@ -687,7 +733,9 @@ discard block |
||
687 | 733 | |
688 | 734 | final private function verifyConnection() |
689 | 735 | { |
690 | - if (is_null($this->Connection->getCurrentConnectionString())) throw new \Exception('Not set connection.'); |
|
736 | + if (is_null($this->Connection->getCurrentConnectionString())) { |
|
737 | + throw new \Exception('Not set connection.'); |
|
738 | + } |
|
691 | 739 | } |
692 | 740 | |
693 | 741 | protected function setTableName($tableName) |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | { |
28 | 28 | if (!($data instanceof self)) throw new \Exception(" It's not a model."); |
29 | 29 | |
30 | - $data = array_map(function ($object) { return $object->toArray(); }, $data); |
|
30 | + $data = array_map(function($object) { return $object->toArray(); }, $data); |
|
31 | 31 | |
32 | 32 | return $data; |
33 | 33 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | if (is_null($offset)) { |
67 | 67 | $data[] = $value; |
68 | - } else { |
|
68 | + }else { |
|
69 | 69 | $data[$offset] = $value; |
70 | 70 | } |
71 | 71 | } |
@@ -25,7 +25,9 @@ |
||
25 | 25 | */ |
26 | 26 | public static function toList($data) |
27 | 27 | { |
28 | - if (!($data instanceof self)) throw new \Exception(" It's not a model."); |
|
28 | + if (!($data instanceof self)) { |
|
29 | + throw new \Exception(" It's not a model."); |
|
30 | + } |
|
29 | 31 | |
30 | 32 | $data = array_map(function ($object) { return $object->toArray(); }, $data); |
31 | 33 |
@@ -101,8 +101,7 @@ discard block |
||
101 | 101 | $default = $this->Config->getDefault(); |
102 | 102 | |
103 | 103 | $name = is_null($default) ? |
104 | - @end(array_keys($configs ?: [])) : |
|
105 | - $default; |
|
104 | + @end(array_keys($configs ?: [])) : $default; |
|
106 | 105 | |
107 | 106 | $this->open($name); |
108 | 107 | } |
@@ -133,7 +132,7 @@ discard block |
||
133 | 132 | } catch (\Exception $e) { |
134 | 133 | throw $e; |
135 | 134 | } |
136 | - } else { |
|
135 | + }else { |
|
137 | 136 | |
138 | 137 | throw new \Exception("This connection isn't actived."); |
139 | 138 | } |