Passed
Push — master ( 581fc9...c2c5c3 )
by Henri
01:16
created
examples/Insert.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use HnrAzevedo\Datamanager\DatamanagerException;
12 12
 use Model\User;
13 13
 
14
-try{
14
+try {
15 15
     $entity = new User();
16 16
 
17 17
     /* Set new info for insert in database */
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     /* Insert entity in database */
25 25
     $entity->persist();
26 26
 
27
-}catch(DatamanagerException $er){
27
+} catch (DatamanagerException $er) {
28 28
 
29 29
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
30 30
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
     /* Insert entity in database */
25 25
     $entity->persist();
26 26
 
27
-}catch(DatamanagerException $er){
27
+} catch(DatamanagerException $er){
28 28
 
29 29
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
30 30
 
Please login to merge, or discard this patch.
src/SynchronizeTrait.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@  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;
9 9
     protected ?string $primary = null;
10 10
     protected bool $full = false;
11
-    protected static ?array $describe = null;
11
+    protected static ? array $describe = null;
12 12
 
13 13
     protected function synchronize(string $table, ?string $primary = null)
14 14
     {
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
     {
44 44
         $type = $value;
45 45
 
46
-        if(strpos($value,'(')){
47
-            $type = (in_array( substr($value, 0, strpos($value,'(')) , ['varchar','char','text'])) ? 'string' : $type;
48
-            $type = (in_array( substr($value, 0, strpos($value,'(')) , ['tinyint','mediumint','smallint','bigtint','int'])) ? 'int' : $type;
49
-            $type = (in_array( substr($value, 0, strpos($value,'(')) , ['decimal','float','double','real'])) ? 'float' : $type;
46
+        if (strpos($value, '(')) {
47
+            $type = (in_array(substr($value, 0, strpos($value, '(')), ['varchar', 'char', 'text'])) ? 'string' : $type;
48
+            $type = (in_array(substr($value, 0, strpos($value, '(')), ['tinyint', 'mediumint', 'smallint', 'bigtint', 'int'])) ? 'int' : $type;
49
+            $type = (in_array(substr($value, 0, strpos($value, '(')), ['decimal', 'float', 'double', 'real'])) ? 'float' : $type;
50 50
         }
51 51
 
52 52
         $this->mountTable_Maxlength($field, $type, $value);
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 
56 56
     protected function mountTable_Maxlength(string $field, string $type, $default = null)
57 57
     {
58
-        $maxlength = (in_array( $type , ['string','float','int'])) ? substr($default,(strpos($default,'(')+1),-1) : 0;
59
-        $maxlength = (in_array( $type , ['date'])) ? 10 : $maxlength;
60
-        $maxlength = (in_array( $type , ['datetime'])) ? 19 : $maxlength;
61
-        $maxlength = (in_array( $type , ['boolean'])) ? 1 : $maxlength;
58
+        $maxlength = (in_array($type, ['string', 'float', 'int'])) ? substr($default, (strpos($default, '(') + 1), -1) : 0;
59
+        $maxlength = (in_array($type, ['date'])) ? 10 : $maxlength;
60
+        $maxlength = (in_array($type, ['datetime'])) ? 19 : $maxlength;
61
+        $maxlength = (in_array($type, ['boolean'])) ? 1 : $maxlength;
62 62
         $this->$field = ['maxlength' => $maxlength];
63 63
     }
64 64
 
Please login to merge, or discard this patch.
src/Datamanager.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  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
     protected array $between = [];    
16 16
 
17 17
     public function getData(): ?array
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         $deniable = (is_array($deniable)) ? $deniable : [$deniable];
30 30
 
31 31
         foreach ($deniable as $field) {
32
-            if(!array_key_exists($field,$this->data)){
32
+            if (!array_key_exists($field, $this->data)) {
33 33
                 throw new DatamanagerException("{$field} field does not exist in the table {$this->table}.");
34 34
             }
35 35
             $this->excepts[$field] = true;
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 
49 49
     public function orderBy(string $field, string $ord = 'ASC')
50 50
     {
51
-        $this->isSettable( str_replace(['asc','ASC','desc','DESC',' '],'',$field) );
51
+        $this->isSettable(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field));
52 52
 
53
-        $ord = (strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')) ? '' : $ord;
53
+        $ord = (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) ? '' : $ord;
54 54
 
55 55
         $this->order = " ORDER BY {$field} {$ord} ";
56 56
         return $this;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
             $this->select[$field] = true;
67 67
         }
68 68
 
69
-        if(!is_null($this->primary)){
69
+        if (!is_null($this->primary)) {
70 70
             $this->select[$this->primary] = true;
71 71
         }
72 72
         return $this;
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
 
75 75
     public function where(array $where)
76 76
     {
77
-        $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? '';
77
+        $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? '';
78 78
         $w = [];
79 79
         foreach ($where as $condition => $values) {
80 80
 
81
-            if(!is_array($values)){
81
+            if (!is_array($values)) {
82 82
                 $w['AND'][] = $values;
83 83
                 continue;
84 84
             }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
                        
90 90
         }
91 91
 
92
-        $this->where = array_merge($this->where,$w);
92
+        $this->where = array_merge($this->where, $w);
93 93
 
94 94
         return $this;
95 95
     }
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         $string = '';
150 150
         foreach ($this->data as $key => $value) {
151 151
 
152
-            if(gettype($value)==='object'){
152
+            if (gettype($value) === 'object') {
153 153
                 $value = $value->getData()[$this->primary]['value'];
154 154
             }
155 155
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 
161 161
     private function removeById(): bool
162 162
     {
163
-        $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}");
163
+        $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}");
164 164
 
165 165
         $this->check_fail();
166 166
 
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 
170 170
     public function findById($id)
171 171
     {
172
-        return $this->where([$this->primary,'=',$id]);
172
+        return $this->where([$this->primary, '=', $id]);
173 173
     }
174 174
 
175 175
     public function execute()
176 176
     {
177
-        if(!is_null($this->clause) && $this->clause == 'remove'){
177
+        if (!is_null($this->clause) && $this->clause == 'remove') {
178 178
             return $this->remove(true);
179 179
         }
180 180
 
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
         
183 183
         $this->mountSelect();
184 184
         
185
-        $where = substr($this->mountWhereExec()['where'],0,-1);
186
-        $where .= substr($this->mountBetweenExec()['where'],0,-1);
185
+        $where = substr($this->mountWhereExec()['where'], 0, -1);
186
+        $where .= substr($this->mountBetweenExec()['where'], 0, -1);
187 187
 
188 188
         $this->query .= " WHERE {$where} ";
189 189
 
Please login to merge, or discard this patch.
src/DataTrait.php 1 patch
Spacing   +19 added lines, -19 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,7 +44,7 @@  discard block
 block discarded – undo
44 44
         $return = ['data' => []];
45 45
 
46 46
         foreach ($this->data as $key => $value) {
47
-            if($this->upgradeable($key) && !$this->isIncremented($key)){
47
+            if ($this->upgradeable($key) && !$this->isIncremented($key)) {
48 48
                 $return['data'][$key] = $this->data[$key]['value'];
49 49
             }
50 50
         }
@@ -59,15 +59,15 @@  discard block
 block discarded – undo
59 59
 
60 60
             $key = (!$key) ? '' : " {$key} ";
61 61
 
62
-            if(!is_array($value[0])){
62
+            if (!is_array($value[0])) {
63 63
                 $return['where'] .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]} ";
64 64
                 $return['data']["q_{$value[0]}"] = $value[2];
65 65
                 continue;
66 66
             }
67 67
             
68
-            for($i = 0; $i < count($value); $i++){
68
+            for ($i = 0; $i < count($value); $i++) {
69 69
                 
70
-                if(!is_array($value[$i][2])){
70
+                if (!is_array($value[$i][2])) {
71 71
                     $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} :q_{$value[$i][0]} ";
72 72
                     $return['data']["q_{$value[$i][0]}"] = $value[$i][2];
73 73
                     continue;
@@ -75,12 +75,12 @@  discard block
 block discarded – undo
75 75
 
76 76
                 $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} (";
77 77
 
78
-                foreach($value[$i][2] as $v => $valu){
78
+                foreach ($value[$i][2] as $v => $valu) {
79 79
                     $return['where'] .= " :q_{$value[$i][0]}_{$v},";
80 80
                     $return['data']["q_{$value[$i][0]}_{$v}"] = $valu;
81 81
                 }
82 82
 
83
-                $return['where'] = substr($return['where'],0,-1) .') ';
83
+                $return['where'] = substr($return['where'], 0, -1).') ';
84 84
             }
85 85
         }
86 86
         return $return;
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
     {
91 91
         $return = ['where' => '', 'data' => []];
92 92
 
93
-        foreach($this->between as $field => $value){
94
-            $condition = (count(explode(' ',$field)) > 2) ? ' '.explode(' ',$field)[0].' ' : ' AND ';
95
-            $field = str_replace(['AND','OR',' '],'',$field);
93
+        foreach ($this->between as $field => $value) {
94
+            $condition = (count(explode(' ', $field)) > 2) ? ' '.explode(' ', $field)[0].' ' : ' AND ';
95
+            $field = str_replace(['AND', 'OR', ' '], '', $field);
96 96
             $return['where'] .= " {$condition} {$field} BETWEEN :q_1{$field} AND :q_2{$field} ";
97 97
             $return['data'] = [
98
-                "q_1{$field}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[0]) , 'Y-m-d')),
99
-                "q_2{$field}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[1]) , 'Y-m-d'))
98
+                "q_1{$field}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[0]), 'Y-m-d')),
99
+                "q_2{$field}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[1]), 'Y-m-d'))
100 100
             ];
101 101
         }
102 102
         return $return;
@@ -104,21 +104,21 @@  discard block
 block discarded – undo
104 104
 
105 105
     protected function mountSelect()
106 106
     {
107
-        $select = implode(',',array_keys($this->select));
107
+        $select = implode(',', array_keys($this->select));
108 108
 
109
-        $this->query = str_replace('*', $select,$this->query);
109
+        $this->query = str_replace('*', $select, $this->query);
110 110
     }
111 111
 
112 112
     protected function mountLimit()
113 113
     {
114
-        if(!is_null($this->limit)){
114
+        if (!is_null($this->limit)) {
115 115
             $this->query .= " LIMIT {$this->limit}";
116 116
         }
117 117
     }
118 118
 
119 119
     protected function mountOffset()
120 120
     {
121
-        if(!is_null($this->offset)){
121
+        if (!is_null($this->offset)) {
122 122
             $this->query .= " OFFSET {$this->offset}";
123 123
         }
124 124
     }
Please login to merge, or discard this patch.