Passed
Branch master (2a5401)
by Henri
02:36 queued 01:15
created
src/DataTrait.php 1 patch
Spacing   +20 added lines, -20 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;
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
     {
26 26
         $return = ['data' => '', 'where' => ''];
27 27
         $c = -1;
28
-        foreach($this->where as $clause => $condition){
28
+        foreach ($this->where as $clause => $condition) {
29 29
             $c++;
30
-            if(strlen($clause) === 0){
30
+            if (strlen($clause) === 0) {
31 31
                 $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]}{$c} ";
32 32
                 $return['data'] .= "q_{$condition[0]}={$condition[2]}{$c}&";
33 33
                 continue;
34 34
             }
35 35
                 
36
-            foreach($condition as $value){
36
+            foreach ($condition as $value) {
37 37
                 $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]}{$c} ";
38 38
                 $return['data'] .= "q_{$value[0]}={$value[2]}{$c}&";
39 39
             }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         $return = ['data' => []];
47 47
 
48 48
         foreach ($this->data as $key => $value) {
49
-            if($this->upgradeable($key) && !$this->isIncremented($key)){
49
+            if ($this->upgradeable($key) && !$this->isIncremented($key)) {
50 50
                 $return['data'][$key] = $this->data[$key]['value'];
51 51
             }
52 52
         }
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
     private function mountWheres(array $value, string $key, int $c): array
58 58
     {
59 59
         $return = [];
60
-        for($i = 0; $i < count($value); $i++){
60
+        for ($i = 0; $i < count($value); $i++) {
61 61
                 
62
-            if(!is_array($value[$i][2])){
62
+            if (!is_array($value[$i][2])) {
63 63
                 $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} :q_{$value[$i][0]}{$c}{$i} ";
64 64
                 $return['data']["q_{$value[$i][0]}{$c}{$i}"] = $value[$i][2];
65 65
                 continue;
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
 
68 68
             $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} (";
69 69
 
70
-            foreach($value[$i][2] as $v => $valu){
70
+            foreach ($value[$i][2] as $v => $valu) {
71 71
                 $return['where'] .= " :q_{$value[$i][0]}{$c}{$i}_{$v},";
72 72
                 $return['data']["q_{$value[$i][0]}{$c}{$i}_{$v}"] = $valu;
73 73
             }
74 74
 
75
-            $return['where'] = substr($return['where'],0,-1) .') ';
75
+            $return['where'] = substr($return['where'], 0, -1).') ';
76 76
         }
77 77
         return $return;
78 78
     }
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
             $c++;
86 86
             $key = (!$key) ? '' : " {$key} ";
87 87
 
88
-            if(!is_array($value[0])){
88
+            if (!is_array($value[0])) {
89 89
                 $return['where'] .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]}{$c} ";
90 90
                 $return['data']["q_{$value[0]}{$c}"] = $value[2];
91 91
                 continue;
92 92
             }
93 93
 
94
-            $return = array_merge($return,$this->mountWheres($value, $key, $c));
94
+            $return = array_merge($return, $this->mountWheres($value, $key, $c));
95 95
             
96 96
         }
97 97
         return $return;
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
         $return = ['where' => '', 'data' => []];
103 103
 
104 104
         $c = -1;
105
-        foreach($this->between as $field => $value){
105
+        foreach ($this->between as $field => $value) {
106 106
             $c++;
107
-            $condition = (count(explode(' ',$field)) > 2) ? ' '.explode(' ',$field)[0].' ' : ' AND ';
108
-            $field = str_replace(['AND','OR',' '],'',$field);
107
+            $condition = (count(explode(' ', $field)) > 2) ? ' '.explode(' ', $field)[0].' ' : ' AND ';
108
+            $field = str_replace(['AND', 'OR', ' '], '', $field);
109 109
             $return['where'] .= " {$condition} {$field} BETWEEN :q_1{$field}{$c} AND :q_2{$field}{$c} ";
110 110
             $return['data'] = [
111
-                "q_1{$field}{$c}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[0]) , 'Y-m-d')),
112
-                "q_2{$field}{$c}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[1]) , 'Y-m-d'))
111
+                "q_1{$field}{$c}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[0]), 'Y-m-d')),
112
+                "q_2{$field}{$c}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[1]), 'Y-m-d'))
113 113
             ];
114 114
         }
115 115
         return $return;
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
 
118 118
     protected function mountSelect()
119 119
     {
120
-        $select = implode(',',array_keys($this->select));
120
+        $select = implode(',', array_keys($this->select));
121 121
 
122
-        $this->query = str_replace('*', $select,$this->query);
122
+        $this->query = str_replace('*', $select, $this->query);
123 123
     }
124 124
 
125 125
     protected function mountLimit()
126 126
     {
127
-        if(!is_null($this->limit)){
127
+        if (!is_null($this->limit)) {
128 128
             $this->query .= " LIMIT {$this->limit}";
129 129
         }
130 130
     }
131 131
 
132 132
     protected function mountOffset()
133 133
     {
134
-        if(!is_null($this->offset)){
134
+        if (!is_null($this->offset)) {
135 135
             $this->query .= " OFFSET {$this->offset}";
136 136
         }
137 137
     }
Please login to merge, or discard this patch.