Passed
Branch master (8f2ee9)
by Henri
02:28 queued 01:06
created
src/Datamanager.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
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
 
16
-    public function __set(string $prop,$value)
16
+    public function __set(string $prop, $value)
17 17
     {
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;
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $deniable = (is_array($deniable)) ? $deniable : [$deniable];
52 52
 
53 53
         foreach ($deniable as $field) {
54
-            if(!array_key_exists($field,$this->data)){
54
+            if (!array_key_exists($field, $this->data)) {
55 55
                 throw new Exception("{$field} field does not exist in the table {$this->table}.");
56 56
             }
57 57
 
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
 
72 72
     public function orderBy(string $field, string $ord = 'ASC')
73 73
     {
74
-        $this->isSettable( str_replace(['asc','ASC','desc','DESC',' '],'',$field) );
74
+        $this->isSettable(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field));
75 75
 
76
-        $ord = (strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')) ? '' : $ord;
76
+        $ord = (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) ? '' : $ord;
77 77
 
78 78
         $this->order = " ORDER BY {$field} {$ord} ";
79 79
         return $this;
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 
98 98
     public function where(array $where)
99 99
     {
100
-        $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? '';
100
+        $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? '';
101 101
         $w = [];
102 102
         foreach ($where as $condition => $values) {
103 103
 
104
-            if(!is_array($values)){
104
+            if (!is_array($values)) {
105 105
                 $w['AND'][] = $values;
106 106
                 continue;
107 107
             }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                        
113 113
         }
114 114
 
115
-        $this->where = array_merge($this->where,$w);
115
+        $this->where = array_merge($this->where, $w);
116 116
 
117 117
         return $this;
118 118
     }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
         $string = '';
167 167
         foreach ($this->data as $key => $value) {
168 168
 
169
-            if(gettype($value)==='object'){
169
+            if (gettype($value) === 'object') {
170 170
                 $value = $value->getData()[$this->primary]['value'];
171 171
             }
172 172
 
@@ -177,19 +177,19 @@  discard block
 block discarded – undo
177 177
 
178 178
     public function remove(?bool $exec = false)
179 179
     {
180
-        if(!$exec){
180
+        if (!$exec) {
181 181
             $this->clause = 'remove';    
182 182
             return $this;
183 183
         }
184 184
 
185 185
         $this->clause = null;
186 186
 
187
-        if(count($this->where) == 1){
187
+        if (count($this->where) == 1) {
188 188
             $this->removeById();
189 189
             return $this;
190 190
         }
191 191
 
192
-        $this->delete($this->mountRemove()['where'], substr( $this->mountRemove()['data'] ,0,-1) );
192
+        $this->delete($this->mountRemove()['where'], substr($this->mountRemove()['data'], 0, -1));
193 193
 
194 194
         $this->check_fail();
195 195
             
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 
199 199
     private function removeById(): bool
200 200
     {
201
-        $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}");
201
+        $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}");
202 202
 
203 203
         $this->check_fail();
204 204
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         $data = [];
213 213
 
214 214
         foreach ($this->data as $key => $value) {
215
-            if(strstr($this->data[$key]['extra'],'auto_increment')){
215
+            if (strstr($this->data[$key]['extra'], 'auto_increment')) {
216 216
                 continue;
217 217
             }
218 218
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         }
225 225
 
226 226
         $this->transaction('begin');
227
-        try{
227
+        try {
228 228
            
229 229
             $id = $this->insert($data);
230 230
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             
235 235
             $this->transaction('commit');
236 236
 
237
-        }catch(Exception $er){
237
+        } catch (Exception $er) {
238 238
             $this->transaction('rollback');
239 239
             throw $er;
240 240
         }
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 
245 245
     public function toEntity()
246 246
     {
247
-        if($this->getCount() === 0){
247
+        if ($this->getCount() === 0) {
248 248
             return null;
249 249
         }
250 250
 
251 251
         $entity = $this->setByDatabase($this->result[0]);
252 252
 
253
-        if(count($this->result) > 1){
253
+        if (count($this->result) > 1) {
254 254
             $entity = [];
255 255
             foreach ($this->result as $key => $value) {
256 256
                 $entity[] = $this->setByDatabase($value);
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
 
263 263
     public function findById($id)
264 264
     {
265
-        return $this->where([$this->primary,'=',$id]);
265
+        return $this->where([$this->primary, '=', $id]);
266 266
     }
267 267
 
268 268
     public function execute()
269 269
     {
270
-        if(!is_null($this->clause) && $this->clause == 'remove'){
270
+        if (!is_null($this->clause) && $this->clause == 'remove') {
271 271
             return $this->remove(true);
272 272
         }
273 273
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         
276 276
         $this->mountSelect();
277 277
         
278
-        $where = substr($this->mountWhereExec()['where'],0,-1);
278
+        $where = substr($this->mountWhereExec()['where'], 0, -1);
279 279
         $this->query .= " WHERE {$where} ";
280 280
 
281 281
         $this->query .= $this->order;
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     {
304 304
         $this->transaction('begin');
305 305
 
306
-        try{
306
+        try {
307 307
             $this->update(
308 308
                 $this->mountSave()['data'],
309 309
                 "{$this->primary}=:{$this->primary}", 
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
             $this->check_fail();
314 314
 
315 315
             $this->transaction('commit');
316
-        }catch(Exception $er){
316
+        } catch (Exception $er) {
317 317
             $this->transaction('rollback');
318 318
             throw $er;
319 319
         }
Please login to merge, or discard this patch.
src/DataTrait.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,11 +44,11 @@  discard block
 block discarded – undo
44 44
         $return = ['data' => []];
45 45
 
46 46
         foreach ($this->data as $key => $value) {
47
-            if(strstr($this->data[$key]['extra'],'auto_increment') && $key !== $this->primary){
47
+            if (strstr($this->data[$key]['extra'], 'auto_increment') && $key !== $this->primary) {
48 48
                 continue;
49 49
             }
50 50
 
51
-            if(($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key){
51
+            if (($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key) {
52 52
                 $return['data'][$key] = $this->data[$key]['value'];
53 53
             }
54 54
         }
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
             $key = (!$key) ? '' : " {$key} ";
66 66
 
67
-            if(is_array($value[0])){
67
+            if (is_array($value[0])) {
68 68
 
69 69
                 foreach ($value as $k => $v) {
70 70
                     $return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} ";
@@ -83,21 +83,21 @@  discard block
 block discarded – undo
83 83
 
84 84
     protected function mountSelect()
85 85
     {
86
-        $select = implode(',',array_keys($this->select));
86
+        $select = implode(',', array_keys($this->select));
87 87
 
88
-        $this->query = str_replace('*', $select,$this->query);
88
+        $this->query = str_replace('*', $select, $this->query);
89 89
     }
90 90
 
91 91
     protected function mountLimit()
92 92
     {
93
-        if(!is_null($this->limit)){
93
+        if (!is_null($this->limit)) {
94 94
             $this->query .= " LIMIT {$this->limit}";
95 95
         }
96 96
     }
97 97
 
98 98
     protected function mountOffset()
99 99
     {
100
-        if(!is_null($this->offset)){
100
+        if (!is_null($this->offset)) {
101 101
             $this->query .= " OFFSET {$this->offset}";
102 102
         }
103 103
     }
Please login to merge, or discard this patch.