@@ -4,36 +4,36 @@ discard block |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -trait CheckTrait{ |
|
7 | +trait CheckTrait { |
|
8 | 8 | |
9 | 9 | protected function check_where_array(array $where) |
10 | 10 | { |
11 | - if(count($where) != 3){ |
|
12 | - throw new Exception("Condition where set incorrectly: ".implode(' ',$where)); |
|
11 | + if (count($where) != 3) { |
|
12 | + throw new Exception("Condition where set incorrectly: ".implode(' ', $where)); |
|
13 | 13 | } |
14 | 14 | |
15 | - if(!array_key_exists($where[0],$this->data) && $this->full){ |
|
15 | + if (!array_key_exists($where[0], $this->data) && $this->full) { |
|
16 | 16 | throw new Exception("{$where[0]} field does not exist in the table {$this->table}."); |
17 | 17 | } |
18 | 18 | } |
19 | 19 | |
20 | 20 | protected function isSettable(string $prop) |
21 | 21 | { |
22 | - if($this->full && !array_key_exists($prop,$this->data)){ |
|
22 | + if ($this->full && !array_key_exists($prop, $this->data)) { |
|
23 | 23 | throw new Exception("{$prop} field does not exist in the table {$this->table}."); |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | 27 | protected function checkLimit() |
28 | 28 | { |
29 | - if(is_null($this->limit)){ |
|
29 | + if (is_null($this->limit)) { |
|
30 | 30 | throw new Exception("The limit must be set before the offset."); |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - protected function checkMaxlength(string $field, $val , $max) |
|
34 | + protected function checkMaxlength(string $field, $val, $max) |
|
35 | 35 | { |
36 | - if(strlen($val) > $max){ |
|
36 | + if (strlen($val) > $max) { |
|
37 | 37 | throw new Exception("The information provided for column {$field} of table {$this->table} exceeded that allowed."); |
38 | 38 | } |
39 | 39 | } |
@@ -45,6 +45,6 @@ discard block |
||
45 | 45 | |
46 | 46 | protected function isIncremented(string $field): bool |
47 | 47 | { |
48 | - return ( strstr($this->data[$field]['extra'],'auto_increment') && $field !== $this->primary ); |
|
48 | + return (strstr($this->data[$field]['extra'], 'auto_increment') && $field !== $this->primary); |
|
49 | 49 | } |
50 | 50 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Datamanager; |
4 | 4 | |
5 | -trait DataTrait{ |
|
5 | +trait DataTrait { |
|
6 | 6 | use CrudTrait, CheckTrait; |
7 | 7 | |
8 | 8 | protected ?string $table = null; |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | protected function mountRemove(): array |
25 | 25 | { |
26 | 26 | $return = ['data' => '', 'where' => '']; |
27 | - foreach($this->where as $clause => $condition){ |
|
28 | - if(strlen($clause) === 0){ |
|
27 | + foreach ($this->where as $clause => $condition) { |
|
28 | + if (strlen($clause) === 0) { |
|
29 | 29 | $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]} "; |
30 | 30 | $return['data'] .= "q_{$condition[0]}={$condition[2]}&"; |
31 | 31 | continue; |
32 | 32 | } |
33 | 33 | |
34 | - foreach($condition as $value){ |
|
34 | + foreach ($condition as $value) { |
|
35 | 35 | $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]} "; |
36 | 36 | $return['data'] .= "q_{$value[0]}={$value[2]}&"; |
37 | 37 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $return = ['data' => []]; |
45 | 45 | |
46 | 46 | foreach ($this->data as $key => $value) { |
47 | - if($this->upgradeable($key) && !$this->isIncremented($key)){ |
|
47 | + if ($this->upgradeable($key) && !$this->isIncremented($key)) { |
|
48 | 48 | $return['data'][$key] = $this->data[$key]['value']; |
49 | 49 | } |
50 | 50 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | $key = (!$key) ? '' : " {$key} "; |
62 | 62 | |
63 | - if(is_array($value[0])){ |
|
63 | + if (is_array($value[0])) { |
|
64 | 64 | |
65 | 65 | foreach ($value as $k => $v) { |
66 | 66 | $return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
@@ -79,21 +79,21 @@ discard block |
||
79 | 79 | |
80 | 80 | protected function mountSelect() |
81 | 81 | { |
82 | - $select = implode(',',array_keys($this->select)); |
|
82 | + $select = implode(',', array_keys($this->select)); |
|
83 | 83 | |
84 | - $this->query = str_replace('*', $select,$this->query); |
|
84 | + $this->query = str_replace('*', $select, $this->query); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | protected function mountLimit() |
88 | 88 | { |
89 | - if(!is_null($this->limit)){ |
|
89 | + if (!is_null($this->limit)) { |
|
90 | 90 | $this->query .= " LIMIT {$this->limit}"; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | protected function mountOffset() |
95 | 95 | { |
96 | - if(!is_null($this->offset)){ |
|
96 | + if (!is_null($this->offset)) { |
|
97 | 97 | $this->query .= " OFFSET {$this->offset}"; |
98 | 98 | } |
99 | 99 | } |