@@ -4,36 +4,36 @@ discard block |
||
4 | 4 | |
5 | 5 | use HnrAzevedo\Datamanager\DatamanagerException; |
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 DatamanagerException("Condition where set incorrectly: ".implode(' ',$where)); |
|
11 | + if (count($where) != 3) { |
|
12 | + throw new DatamanagerException("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 DatamanagerException("{$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 DatamanagerException("{$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 DatamanagerException("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 DatamanagerException("The information provided for column {$field} of table {$this->table} exceeded that allowed."); |
38 | 38 | } |
39 | 39 | } |
@@ -45,18 +45,18 @@ 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 | |
51 | 51 | protected function checkForChanges(): bool |
52 | 52 | { |
53 | 53 | $hasChanges = false; |
54 | - foreach($this->data as $data){ |
|
55 | - if($data['changed']){ |
|
54 | + foreach ($this->data as $data) { |
|
55 | + if ($data['changed']) { |
|
56 | 56 | $hasChanges = true; |
57 | 57 | } |
58 | 58 | } |
59 | - if(!$hasChanges){ |
|
59 | + if (!$hasChanges) { |
|
60 | 60 | throw new DatamanagerException('There were no changes to be saved in the database.'); |
61 | 61 | } |
62 | 62 | return true; |
@@ -4,16 +4,16 @@ discard block |
||
4 | 4 | |
5 | 5 | use HnrAzevedo\Datamanager\DatamanagerException; |
6 | 6 | |
7 | -trait EntityTrait{ |
|
7 | +trait EntityTrait { |
|
8 | 8 | public function toEntity() |
9 | 9 | { |
10 | - if($this->getCount() === 0){ |
|
10 | + if ($this->getCount() === 0) { |
|
11 | 11 | return null; |
12 | 12 | } |
13 | 13 | |
14 | 14 | $entity = $this->setByDatabase($this->result[0]); |
15 | 15 | |
16 | - if(count($this->result) > 1){ |
|
16 | + if (count($this->result) > 1) { |
|
17 | 17 | $entity = []; |
18 | 18 | foreach ($this->result as $key => $value) { |
19 | 19 | $entity[] = $this->setByDatabase($value); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | $data = []; |
31 | 31 | |
32 | 32 | foreach ($this->data as $key => $value) { |
33 | - if(strstr($this->data[$key]['extra'],'auto_increment')){ |
|
33 | + if (strstr($this->data[$key]['extra'], 'auto_increment')) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | 36 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | $this->transaction('begin'); |
45 | - try{ |
|
45 | + try { |
|
46 | 46 | |
47 | 47 | $id = $this->insert($data); |
48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | $this->transaction('commit'); |
56 | 56 | |
57 | - }catch(DatamanagerException $er){ |
|
57 | + } catch (DatamanagerException $er) { |
|
58 | 58 | $this->transaction('rollback'); |
59 | 59 | throw $er; |
60 | 60 | } |
@@ -64,19 +64,19 @@ discard block |
||
64 | 64 | |
65 | 65 | public function remove(bool $exec = false) |
66 | 66 | { |
67 | - if(!$exec){ |
|
67 | + if (!$exec) { |
|
68 | 68 | $this->clause = 'remove'; |
69 | 69 | return $this; |
70 | 70 | } |
71 | 71 | |
72 | 72 | $this->clause = null; |
73 | 73 | |
74 | - if(count($this->where) == 1){ |
|
74 | + if (count($this->where) == 1) { |
|
75 | 75 | $this->removeById(); |
76 | 76 | return $this; |
77 | 77 | } |
78 | 78 | |
79 | - $this->delete($this->mountRemove()['where'], substr( $this->mountRemove()['data'] ,0,-1) ); |
|
79 | + $this->delete($this->mountRemove()['where'], substr($this->mountRemove()['data'], 0, -1)); |
|
80 | 80 | |
81 | 81 | $this->check_fail(); |
82 | 82 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | { |
88 | 88 | $this->transaction('begin'); |
89 | 89 | |
90 | - try{ |
|
90 | + try { |
|
91 | 91 | $this->checkForChanges(); |
92 | 92 | |
93 | 93 | $this->update( |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $this->check_fail(); |
100 | 100 | |
101 | 101 | $this->transaction('commit'); |
102 | - }catch(DatamanagerException $er){ |
|
102 | + } catch (DatamanagerException $er) { |
|
103 | 103 | $this->transaction('rollback'); |
104 | 104 | throw $er; |
105 | 105 | } |