Passed
Push — master ( b12b63...8e6e26 )
by Henri
08:15
created
src/CrudTrait.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use Exception;
7 7
 use PDO;
8 8
 
9
-trait CrudTrait{
9
+trait CrudTrait {
10 10
 
11 11
     protected ?DatamanagerException $fail = null;
12 12
     protected string $lastQuery = '';
@@ -14,18 +14,18 @@  discard block
 block discarded – undo
14 14
 
15 15
     protected function check_fail()
16 16
     {
17
-        if(!is_null($this->fail)){
17
+        if (!is_null($this->fail)) {
18 18
             throw $this->fail;
19 19
         }
20 20
     }
21 21
 
22 22
     protected function transaction(string $transaction): ?bool
23 23
     {
24
-        if(array_key_exists($transaction,['begin','commit','rollback'])){
24
+        if (array_key_exists($transaction, ['begin', 'commit', 'rollback'])) {
25 25
             throw new DatamanagerException("{$transaction} é um estado inválido para transações.");
26 26
         }
27 27
 
28
-        if(!Connect::getInstance()->inTransaction()){
28
+        if (!Connect::getInstance()->inTransaction()) {
29 29
            return Connect::getInstance()->beginTransaction();
30 30
         }
31 31
 
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
         return false;
37 37
     }
38 38
 
39
-    protected function select(string $query,array $data): ?array
39
+    protected function select(string $query, array $data): ?array
40 40
     {
41
-        try{
41
+        try {
42 42
             $stmt = Connect::getInstance()->prepare("{$query}");
43 43
 
44 44
             $this->lastQuery = "{$query}";
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
             $stmt->execute($data);
48 48
             return $stmt->fetchAll(PDO::FETCH_ASSOC);
49
-        }catch(Exception $exception){
49
+        } catch (Exception $exception) {
50 50
             $this->fail = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
51 51
         }
52 52
         return [];
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
     protected function describe(): array
56 56
     {
57
-        try{
57
+        try {
58 58
             $stmt = Connect::getInstance()->prepare("DESCRIBE {$this->table}");
59 59
 
60 60
             $this->lastQuery = "DESCRIBE {$this->table}";
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
             $stmt->execute();
64 64
             return $stmt->fetchAll(PDO::FETCH_ASSOC);
65
-        }catch(Exception $exception){
65
+        } catch (Exception $exception) {
66 66
             $this->fail = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
67 67
             return [];
68 68
         }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     {
73 73
         try {
74 74
             $columns = implode(", ", array_keys($data));
75
-            $values = ":" . implode(", :", array_keys($data));
75
+            $values = ":".implode(", :", array_keys($data));
76 76
 
77 77
             $stmt = Connect::getInstance()->prepare("INSERT INTO {$this->table} ({$columns}) VALUES ({$values})");
78 78
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
             $this->lastQuery = "DELETE FROM {$this->table} WHERE {$terms}";
126 126
             $this->lastData = [];
127 127
 
128
-            if($params){
128
+            if ($params) {
129 129
                 parse_str($params, $arr);
130 130
                 $this->lastData = $arr;
131 131
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
             $stmt->execute($data);
48 48
             return $stmt->fetchAll(PDO::FETCH_ASSOC);
49
-        }catch(Exception $exception){
49
+        } catch(Exception $exception){
50 50
             $this->fail = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
51 51
         }
52 52
         return [];
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
             $stmt->execute();
64 64
             return $stmt->fetchAll(PDO::FETCH_ASSOC);
65
-        }catch(Exception $exception){
65
+        } catch(Exception $exception){
66 66
             $this->fail = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
67 67
             return [];
68 68
         }
Please login to merge, or discard this patch.
src/Datamanager.php 1 patch
Spacing   +15 added lines, -15 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'): Datamanager
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): Datamanager
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): Datamanager
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(): Datamanager
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
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 
205 205
         $this->count = count($this->result);
206 206
         $this->query = null;
207
-        $this->where = [''=> ["1",'=',"1"] ];
207
+        $this->where = [''=> ["1", '=', "1"]];
208 208
 
209 209
         return $this;
210 210
     }
Please login to merge, or discard this patch.
src/DebugTrait.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@
 block discarded – undo
9 9
 
10 10
     public function debug(bool $array = false)
11 11
     {
12
-        if($array){
12
+        if ($array) {
13 13
             return ['query' => $this->lastQuery, 'data' => $this->lastData];
14 14
         }
15 15
         
16 16
         $query = $this->lastQuery;
17 17
 
18
-        foreach($this->lastData as $name => $value){
19
-            $query = str_replace(":{$name}","'{$value}'",$query);
18
+        foreach ($this->lastData as $name => $value) {
19
+            $query = str_replace(":{$name}", "'{$value}'", $query);
20 20
         }
21 21
 
22 22
         return $query;
Please login to merge, or discard this patch.
src/EntityTrait.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use HnrAzevedo\Datamanager\DatamanagerException;
6 6
 
7
-trait EntityTrait{
7
+trait EntityTrait {
8 8
     use CheckTrait;
9 9
 
10 10
     protected string $lastQuery = '';
@@ -12,13 +12,13 @@  discard block
 block discarded – undo
12 12
     
13 13
     public function toEntity()
14 14
     {
15
-        if($this->getCount() === 0){
15
+        if ($this->getCount() === 0) {
16 16
             return null;
17 17
         }
18 18
 
19 19
         $entity = $this->setByDatabase($this->result[0]);
20 20
 
21
-        if(count($this->result) > 1){
21
+        if (count($this->result) > 1) {
22 22
             $entity = [];
23 23
             foreach ($this->result as $key => $value) {
24 24
                 $entity[] = $this->setByDatabase($value);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
         $data = [];
36 36
 
37 37
         foreach ($this->data as $key => $value) {
38
-            if(strstr($this->data[$key]['extra'],'auto_increment')){
38
+            if (strstr($this->data[$key]['extra'], 'auto_increment')) {
39 39
                 continue;
40 40
             }
41 41
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         }
48 48
 
49 49
         $this->transaction('begin');
50
-        try{
50
+        try {
51 51
 
52 52
             $this->checkUniques($data);
53 53
            
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
             
62 62
             $this->transaction('commit');
63 63
 
64
-        }catch(DatamanagerException $er){
64
+        } catch (DatamanagerException $er) {
65 65
             $this->transaction('rollback');
66 66
             throw $er;
67 67
         }
@@ -71,21 +71,21 @@  discard block
 block discarded – undo
71 71
 
72 72
     public function remove(bool $exec = false)
73 73
     {
74
-        if(!$exec){
74
+        if (!$exec) {
75 75
             $this->clause = 'remove';    
76 76
             return $this;
77 77
         }
78 78
 
79 79
         $this->clause = null;
80 80
 
81
-        if(count($this->where) == 1){
81
+        if (count($this->where) == 1) {
82 82
             $this->removeById();
83 83
             return $this;
84 84
         }
85 85
 
86 86
         $this->delete(
87 87
             $this->mountRemove()['where'], 
88
-            substr( $this->mountRemove()['data'] ,0,-1)
88
+            substr($this->mountRemove()['data'], 0, -1)
89 89
         );
90 90
 
91 91
         $this->check_fail();
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     {
98 98
         $this->transaction('begin');
99 99
 
100
-        try{
100
+        try {
101 101
             $this->checkForChanges();
102 102
 
103 103
             $this->update(
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
             $this->check_fail();
110 110
 
111 111
             $this->transaction('commit');
112
-        }catch(DatamanagerException $er){
112
+        } catch (DatamanagerException $er) {
113 113
             $this->transaction('rollback');
114 114
             throw $er;
115 115
         }
Please login to merge, or discard this patch.