@@ -156,13 +156,17 @@ |
||
156 | 156 | switch (!is_object($this->data) && $count = count($this->data)) { |
157 | 157 | case (!isset($this->data[0]) && !empty($this->data)): |
158 | 158 | foreach($this->excepts as $except) { |
159 | - if(isset($this->data[$except])) unset($this->data[$except]); |
|
159 | + if(isset($this->data[$except])) { |
|
160 | + unset($this->data[$except]); |
|
161 | + } |
|
160 | 162 | } |
161 | 163 | break; |
162 | 164 | case ($count >= 2 && isset($this->data[0])): |
163 | 165 | foreach($this->excepts as $except) { |
164 | 166 | for($i = 0; $i < $count; $i++) { |
165 | - if(isset($this->data[$i][$except])) unset($this->data[$i][$except]); |
|
167 | + if(isset($this->data[$i][$except])) { |
|
168 | + unset($this->data[$i][$except]); |
|
169 | + } |
|
166 | 170 | } |
167 | 171 | } |
168 | 172 | break; |
@@ -166,8 +166,8 @@ |
||
166 | 166 | } |
167 | 167 | } |
168 | 168 | break; |
169 | - default: |
|
170 | - return []; |
|
169 | + default: |
|
170 | + return []; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -176,17 +176,17 @@ discard block |
||
176 | 176 | */ |
177 | 177 | private function deny() |
178 | 178 | { |
179 | - if(!empty($this->excepts)) { |
|
179 | + if (!empty($this->excepts)) { |
|
180 | 180 | switch (!is_object($this->data) && $count = count($this->data)) { |
181 | 181 | case (!isset($this->data[0]) && !empty($this->data)): |
182 | - foreach($this->excepts as $except) { |
|
183 | - if(isset($this->data[$except])) unset($this->data[$except]); |
|
182 | + foreach ($this->excepts as $except) { |
|
183 | + if (isset($this->data[$except])) unset($this->data[$except]); |
|
184 | 184 | } |
185 | 185 | break; |
186 | 186 | case ($count >= 2 && isset($this->data[0])): |
187 | - foreach($this->excepts as $except) { |
|
188 | - for($i = 0; $i < $count; $i++) { |
|
189 | - if(isset($this->data[$i][$except])) unset($this->data[$i][$except]); |
|
187 | + foreach ($this->excepts as $except) { |
|
188 | + for ($i = 0; $i < $count; $i++) { |
|
189 | + if (isset($this->data[$i][$except])) unset($this->data[$i][$except]); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | break; |
@@ -205,11 +205,10 @@ discard block |
||
205 | 205 | try { |
206 | 206 | $execute = $this->conn->query("SELECT {$this->params} FROM {$this->table} {$this->where} {$this->order} {$this->limit} {$this->offset}"); |
207 | 207 | $execute->rowCount() > 1 ? |
208 | - $this->data = ($this->type ? $execute->fetchAll(PDO::FETCH_CLASS, static::class) : $execute->fetchAll(PDO::FETCH_ASSOC)) : |
|
209 | - $this->data = ($this->type ? $execute->fetchObject(static::class) : $execute->fetch(PDO::FETCH_ASSOC)); |
|
208 | + $this->data = ($this->type ? $execute->fetchAll(PDO::FETCH_CLASS, static::class) : $execute->fetchAll(PDO::FETCH_ASSOC)) : $this->data = ($this->type ? $execute->fetchObject(static::class) : $execute->fetch(PDO::FETCH_ASSOC)); |
|
210 | 209 | $this->deny(); |
211 | 210 | return $this->data; |
212 | - } catch(PDOException $exc) { |
|
211 | + } catch (PDOException $exc) { |
|
213 | 212 | return $exc->getMessage(); |
214 | 213 | } |
215 | 214 | } |
@@ -220,7 +219,7 @@ discard block |
||
220 | 219 | public function destroy() |
221 | 220 | { |
222 | 221 | $primary = $this->primary; |
223 | - if(!isset($this->data->$primary)) { |
|
222 | + if (!isset($this->data->$primary)) { |
|
224 | 223 | throw new Exception("|| Índice primário não encontrado: {$primary} ||"); |
225 | 224 | } |
226 | 225 | |
@@ -234,7 +233,7 @@ discard block |
||
234 | 233 | { |
235 | 234 | $primary = $this->primary; |
236 | 235 | $data = json_decode(json_encode($this->data), true); |
237 | - if(empty($primary) || !isset($data[$primary])) { |
|
236 | + if (empty($primary) || !isset($data[$primary])) { |
|
238 | 237 | throw new Exception("|| Índice primário não encontrado: {$primary} ||"); |
239 | 238 | } |
240 | 239 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $sql = $this->conn->prepare("DELETE FROM {$this->table} WHERE {$this->primary} = :primary"); |
15 | 15 | $sql->bindParam(':primary', $primary); |
16 | 16 | return $sql->execute(); |
17 | - } catch(PDOException $exception) { |
|
17 | + } catch (PDOException $exception) { |
|
18 | 18 | return null; |
19 | 19 | } |
20 | 20 | } |
@@ -30,26 +30,26 @@ discard block |
||
30 | 30 | $params = explode(',', $params); |
31 | 31 | $data = []; |
32 | 32 | $countParams = count($params); |
33 | - for($i = 0; $i < $countParams; $i++) { |
|
34 | - $data[$i] = ":".$params[$i][0].$params[$i][1].$params[$i][2].", "; |
|
33 | + for ($i = 0; $i < $countParams; $i++) { |
|
34 | + $data[$i] = ":" . $params[$i][0] . $params[$i][1] . $params[$i][2] . ", "; |
|
35 | 35 | } |
36 | 36 | $result = ''; |
37 | 37 | $final = array_map(null, $params, $data); |
38 | - foreach($final as $key => $vals) { |
|
39 | - foreach($vals as $chave => $val) { |
|
38 | + foreach ($final as $key => $vals) { |
|
39 | + foreach ($vals as $chave => $val) { |
|
40 | 40 | $result .= str_replace(':', ' = :', $val); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | $result = rtrim($result, ', '); |
44 | 44 | $sql = $this->conn->prepare("UPDATE {$this->table} SET {$result} WHERE {$this->primary} = '{$primary}'"); |
45 | - for($i = 0; $i < $countParams; $i++) { |
|
46 | - $data[$i] = ":".$params[$i][0].$params[$i][1].$params[$i][2]; |
|
45 | + for ($i = 0; $i < $countParams; $i++) { |
|
46 | + $data[$i] = ":" . $params[$i][0] . $params[$i][1] . $params[$i][2]; |
|
47 | 47 | } |
48 | 48 | $countData = count($data); |
49 | - for($i = 0; $i < $countData; $i++) { |
|
49 | + for ($i = 0; $i < $countData; $i++) { |
|
50 | 50 | $sql->bindParam($data[$i], $values[$i]); |
51 | 51 | } |
52 | - if($sql->execute()) { |
|
52 | + if ($sql->execute()) { |
|
53 | 53 | return true; |
54 | 54 | } else { |
55 | 55 | return false; |