Passed
Branch master (a5b543)
by Henri
01:26
created
src/SynchronizeTrait.php 1 patch
Spacing   +9 added lines, -9 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 SynchronizeTrait{
5
+trait SynchronizeTrait {
6 6
     use CrudTrait;
7 7
 
8 8
     protected ?string $table = null;
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
     {
43 43
         $type = $value;
44 44
 
45
-        if(strpos($value,'(')){
46
-            $type = (in_array( substr($value, 0, strpos($value,'(')) , ['varchar','char','text'])) ? 'string' : $type;
47
-            $type = (in_array( substr($value, 0, strpos($value,'(')) , ['tinyint','mediumint','smallint','bigtint','int'])) ? 'int' : $type;
48
-            $type = (in_array( substr($value, 0, strpos($value,'(')) , ['decimal','float','double','real'])) ? 'float' : $type;
45
+        if (strpos($value, '(')) {
46
+            $type = (in_array(substr($value, 0, strpos($value, '(')), ['varchar', 'char', 'text'])) ? 'string' : $type;
47
+            $type = (in_array(substr($value, 0, strpos($value, '(')), ['tinyint', 'mediumint', 'smallint', 'bigtint', 'int'])) ? 'int' : $type;
48
+            $type = (in_array(substr($value, 0, strpos($value, '(')), ['decimal', 'float', 'double', 'real'])) ? 'float' : $type;
49 49
         }
50 50
 
51 51
         $this->mountTable_Maxlength($field, $type, $value);
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
 
55 55
     protected function mountTable_Maxlength(string $field, string $type, $default = null)
56 56
     {
57
-        $maxlength = (in_array( $type , ['string','float','int'])) ? substr($default,(strpos($default,'(')+1),-1) : 0;
58
-        $maxlength = (in_array( $type , ['date'])) ? 10 : $maxlength;
59
-        $maxlength = (in_array( $type , ['datetime'])) ? 19 : $maxlength;
60
-        $maxlength = (in_array( $type , ['boolean'])) ? 1 : $maxlength;
57
+        $maxlength = (in_array($type, ['string', 'float', 'int'])) ? substr($default, (strpos($default, '(') + 1), -1) : 0;
58
+        $maxlength = (in_array($type, ['date'])) ? 10 : $maxlength;
59
+        $maxlength = (in_array($type, ['datetime'])) ? 19 : $maxlength;
60
+        $maxlength = (in_array($type, ['boolean'])) ? 1 : $maxlength;
61 61
         $this->$field = ['maxlength' => $maxlength];
62 62
     }
63 63
 
Please login to merge, or discard this patch.
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 !== null){
180
+        if ($exec !== null) {
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.