@@ -11,21 +11,21 @@ discard block |
||
11 | 11 | protected ?string $table = null; |
12 | 12 | protected ?string $primary = null; |
13 | 13 | protected array $data = []; |
14 | - protected array $where = [''=> ["1",'=',"1"] ]; |
|
14 | + protected array $where = [''=> ["1", '=', "1"]]; |
|
15 | 15 | protected array $between = []; |
16 | 16 | |
17 | - public function __set(string $prop,$value) |
|
17 | + public function __set(string $prop, $value) |
|
18 | 18 | { |
19 | - if(is_array($value)){ |
|
19 | + if (is_array($value)) { |
|
20 | 20 | $attr = array_keys($value)[0]; |
21 | 21 | $this->data[$prop][$attr] = $value[$attr]; |
22 | 22 | return $this; |
23 | 23 | } |
24 | 24 | |
25 | - if($this->full){ |
|
26 | - switch($this->data[$prop]['type']){ |
|
25 | + if ($this->full) { |
|
26 | + switch ($this->data[$prop]['type']) { |
|
27 | 27 | case 'date': |
28 | - $value = (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value) , 'Y-m-d')); |
|
28 | + $value = (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value), 'Y-m-d')); |
|
29 | 29 | break; |
30 | 30 | } |
31 | 31 | } |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | { |
48 | 48 | $this->isSettable($field); |
49 | 49 | |
50 | - if($this->full){ |
|
51 | - switch($this->data[$field]['type']){ |
|
52 | - case 'date': $this->data[$field]['value'] = (date_format( date_create_from_format('Y-m-d' , $this->data[$field]['value'] ) , DATAMANAGER_CONFIG['dateformat'])); |
|
50 | + if ($this->full) { |
|
51 | + switch ($this->data[$field]['type']) { |
|
52 | + case 'date': $this->data[$field]['value'] = (date_format(date_create_from_format('Y-m-d', $this->data[$field]['value']), DATAMANAGER_CONFIG['dateformat'])); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $deniable = (is_array($deniable)) ? $deniable : [$deniable]; |
67 | 67 | |
68 | 68 | foreach ($deniable as $field) { |
69 | - if(!array_key_exists($field,$this->data)){ |
|
69 | + if (!array_key_exists($field, $this->data)) { |
|
70 | 70 | throw new DatamanagerException("{$field} field does not exist in the table {$this->table}."); |
71 | 71 | } |
72 | 72 | $this->excepts[$field] = true; |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | |
86 | 86 | public function orderBy(string $field, string $ord = 'ASC') |
87 | 87 | { |
88 | - $this->isSettable( str_replace(['asc','ASC','desc','DESC',' '],'',$field) ); |
|
88 | + $this->isSettable(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field)); |
|
89 | 89 | |
90 | - $ord = (strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')) ? '' : $ord; |
|
90 | + $ord = (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) ? '' : $ord; |
|
91 | 91 | |
92 | 92 | $this->order = " ORDER BY {$field} {$ord} "; |
93 | 93 | return $this; |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | |
110 | 110 | public function where(array $where) |
111 | 111 | { |
112 | - $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? ''; |
|
112 | + $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? ''; |
|
113 | 113 | $w = []; |
114 | 114 | foreach ($where as $condition => $values) { |
115 | 115 | |
116 | - if(!is_array($values)){ |
|
116 | + if (!is_array($values)) { |
|
117 | 117 | $w['AND'][] = $values; |
118 | 118 | continue; |
119 | 119 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | - $this->where = array_merge($this->where,$w); |
|
127 | + $this->where = array_merge($this->where, $w); |
|
128 | 128 | |
129 | 129 | return $this; |
130 | 130 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $string = ''; |
185 | 185 | foreach ($this->data as $key => $value) { |
186 | 186 | |
187 | - if(gettype($value)==='object'){ |
|
187 | + if (gettype($value) === 'object') { |
|
188 | 188 | $value = $value->getData()[$this->primary]['value']; |
189 | 189 | } |
190 | 190 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | private function removeById(): bool |
197 | 197 | { |
198 | - $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
198 | + $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
199 | 199 | |
200 | 200 | $this->check_fail(); |
201 | 201 | |
@@ -204,12 +204,12 @@ discard block |
||
204 | 204 | |
205 | 205 | public function findById($id) |
206 | 206 | { |
207 | - return $this->where([$this->primary,'=',$id]); |
|
207 | + return $this->where([$this->primary, '=', $id]); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | public function execute() |
211 | 211 | { |
212 | - if(!is_null($this->clause) && $this->clause == 'remove'){ |
|
212 | + if (!is_null($this->clause) && $this->clause == 'remove') { |
|
213 | 213 | return $this->remove(true); |
214 | 214 | } |
215 | 215 | |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | |
218 | 218 | $this->mountSelect(); |
219 | 219 | |
220 | - $where = substr($this->mountWhereExec()['where'],0,-1); |
|
221 | - $where .= substr($this->mountBetweenExec()['where'],0,-1); |
|
220 | + $where = substr($this->mountWhereExec()['where'], 0, -1); |
|
221 | + $where .= substr($this->mountBetweenExec()['where'], 0, -1); |
|
222 | 222 | |
223 | 223 | $this->query .= " WHERE {$where} "; |
224 | 224 |