@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param string $where |
135 | 135 | * @return bool|null |
136 | 136 | */ |
137 | - public function updateObject(object $object, string $where){ |
|
137 | + public function updateObject(object $object, string $where) { |
|
138 | 138 | $args = []; |
139 | 139 | $params = []; |
140 | 140 | foreach ($object as $chave => $valor) { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | /** |
207 | 207 | * @return string|null |
208 | 208 | */ |
209 | - public function getLogSQL():?string |
|
209 | + public function getLogSQL(): ?string |
|
210 | 210 | { |
211 | 211 | return $this->logSQL; |
212 | 212 | } |
@@ -51,8 +51,9 @@ discard block |
||
51 | 51 | $sql = "INSERT INTO {$this->tableName} ({$fields}) VALUES ({$numparams})"; |
52 | 52 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; return; } |
53 | 53 | $result = $this->executeSQL($sql, $values); |
54 | - if (empty($result)) |
|
55 | - return false; |
|
54 | + if (empty($result)) { |
|
55 | + return false; |
|
56 | + } |
|
56 | 57 | return true; |
57 | 58 | } |
58 | 59 | |
@@ -84,8 +85,9 @@ discard block |
||
84 | 85 | $query = "INSERT INTO $this->tableName"; |
85 | 86 | $values = []; |
86 | 87 | $dataColumns = array_keys($params); |
87 | - if (isset ($dataColumns[0])) |
|
88 | - $query .= ' (`' . implode('`, `', $dataColumns) . '`) '; |
|
88 | + if (isset ($dataColumns[0])) { |
|
89 | + $query .= ' (`' . implode('`, `', $dataColumns) . '`) '; |
|
90 | + } |
|
89 | 91 | $query .= ' VALUES ('; |
90 | 92 | |
91 | 93 | foreach ($dataColumns as $index => $column) { |
@@ -97,8 +99,9 @@ discard block |
||
97 | 99 | $query .= ')'; |
98 | 100 | |
99 | 101 | $result = $this->executeSQL($query, $values); |
100 | - if (empty($result)) |
|
101 | - return false; |
|
102 | + if (empty($result)) { |
|
103 | + return false; |
|
104 | + } |
|
102 | 105 | return true; |
103 | 106 | } else { |
104 | 107 | return false; |
@@ -123,8 +126,9 @@ discard block |
||
123 | 126 | if (isset($where)) { $sql .= " WHERE $where"; } |
124 | 127 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; return; } |
125 | 128 | $result = $this->executeSQL($sql, $values); |
126 | - if (empty($result)) |
|
127 | - return false; |
|
129 | + if (empty($result)) { |
|
130 | + return false; |
|
131 | + } |
|
128 | 132 | return true; |
129 | 133 | } |
130 | 134 | |
@@ -165,12 +169,14 @@ discard block |
||
165 | 169 | } |
166 | 170 | $query = rtrim($query, ", "); |
167 | 171 | |
168 | - if (!empty($where)) |
|
169 | - $query .= " WHERE {$where}"; |
|
172 | + if (!empty($where)) { |
|
173 | + $query .= " WHERE {$where}"; |
|
174 | + } |
|
170 | 175 | |
171 | 176 | $result = $this->executeSQL($query, $values); |
172 | - if (empty($result)) |
|
173 | - return false; |
|
177 | + if (empty($result)) { |
|
178 | + return false; |
|
179 | + } |
|
174 | 180 | return true; |
175 | 181 | } else { |
176 | 182 | return false; |
@@ -190,8 +196,9 @@ discard block |
||
190 | 196 | if (!empty($where)) { $sql .= " WHERE $where"; } |
191 | 197 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; return; } |
192 | 198 | $result = $this->executeSQL($sql, $values); |
193 | - if (empty($result)) |
|
194 | - return false; |
|
199 | + if (empty($result)) { |
|
200 | + return false; |
|
201 | + } |
|
195 | 202 | return true; |
196 | 203 | } |
197 | 204 |
@@ -22,8 +22,9 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function __construct(array $params = null) |
24 | 24 | { |
25 | - if (!empty($params)) |
|
26 | - $this->fromMapToModel($params); |
|
25 | + if (!empty($params)) { |
|
26 | + $this->fromMapToModel($params); |
|
27 | + } |
|
27 | 28 | } |
28 | 29 | |
29 | 30 | /** |
@@ -82,7 +83,9 @@ discard block |
||
82 | 83 | $data = (object) $this->toMap(); |
83 | 84 | $re_2 = new ReflectionObject($data); |
84 | 85 | $classname = get_class($this); |
85 | - if ($pos = strrpos($classname, '\\')) $classname = substr($classname, $pos + 1); |
|
86 | + if ($pos = strrpos($classname, '\\')) { |
|
87 | + $classname = substr($classname, $pos + 1); |
|
88 | + } |
|
86 | 89 | return $classname .' {' . implode(', ', array_map( |
87 | 90 | function($p_0) use ($data) |
88 | 91 | { |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function toMap($objArray = null): ?array |
55 | 55 | { |
56 | - $data = $objArray??$this; |
|
56 | + $data = $objArray ?? $this; |
|
57 | 57 | if (is_array($data) || is_object($data)) |
58 | 58 | { |
59 | 59 | $result = []; |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | $re_2 = new ReflectionObject($data); |
84 | 84 | $classname = get_class($this); |
85 | 85 | if ($pos = strrpos($classname, '\\')) $classname = substr($classname, $pos + 1); |
86 | - return $classname .' {' . implode(', ', array_map( |
|
86 | + return $classname . ' {' . implode(', ', array_map( |
|
87 | 87 | function($p_0) use ($data) |
88 | 88 | { |
89 | 89 | $p_0->setAccessible(true); |
90 | - return $p_0->getName() .': '. $p_0->getValue($data); |
|
91 | - }, $re_2->getProperties())) .'}'; |
|
90 | + return $p_0->getName() . ': ' . $p_0->getValue($data); |
|
91 | + }, $re_2->getProperties())) . '}'; |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function __get($attribute):string |
100 | 100 | { |
101 | - return $this->{$attribute}??""; |
|
101 | + return $this->{$attribute} ?? ""; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $this->prepare->execute($params); |
75 | 75 | $this->setLogSQL($query, $params); |
76 | 76 | } catch (PDOException $e) { |
77 | - Connect::setError($e,$query); |
|
77 | + Connect::setError($e, $query); |
|
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param $prepare |
86 | 86 | * @return int |
87 | 87 | */ |
88 | - protected function count($prepare=null): ?int |
|
88 | + protected function count($prepare = null): ?int |
|
89 | 89 | { |
90 | 90 | try { |
91 | 91 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param $prepare |
104 | 104 | * @return array|false |
105 | 105 | */ |
106 | - protected function fetchArrayAssoc($prepare=null): ?array |
|
106 | + protected function fetchArrayAssoc($prepare = null): ?array |
|
107 | 107 | { |
108 | 108 | try { |
109 | 109 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @param $prepare |
121 | 121 | * @return array|false |
122 | 122 | */ |
123 | - protected function fetchArrayObj($prepare=null): ?array |
|
123 | + protected function fetchArrayObj($prepare = null): ?array |
|
124 | 124 | { |
125 | 125 | try { |
126 | 126 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @param String|null $class |
139 | 139 | * @return array|false |
140 | 140 | */ |
141 | - protected function fetchArrayClass($prepare=null, String $class=null): ?array |
|
141 | + protected function fetchArrayClass($prepare = null, String $class = null): ?array |
|
142 | 142 | { |
143 | 143 | try { |
144 | 144 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param $prepare |
157 | 157 | * @return array|false |
158 | 158 | */ |
159 | - protected function fetchOneAssoc($prepare=null): ?array |
|
159 | + protected function fetchOneAssoc($prepare = null): ?array |
|
160 | 160 | { |
161 | 161 | try { |
162 | 162 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param $prepare |
173 | 173 | * @return stdClass|false |
174 | 174 | */ |
175 | - protected function fetchOneObj($prepare=null): ?stdClass |
|
175 | + protected function fetchOneObj($prepare = null): ?stdClass |
|
176 | 176 | { |
177 | 177 | try { |
178 | 178 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @param String|null $class |
190 | 190 | * @return array|false |
191 | 191 | */ |
192 | - protected function fetchOneClass($prepare=null, String $class=null): ?object |
|
192 | + protected function fetchOneClass($prepare = null, String $class = null): ?object |
|
193 | 193 | { |
194 | 194 | try { |
195 | 195 | $prepare = empty($prepare) ? $this->prepare : $prepare; |
@@ -275,21 +275,21 @@ discard block |
||
275 | 275 | private function setLogSQL($sql_string, array $params = null) { |
276 | 276 | if (!empty($params)) { |
277 | 277 | $indexed = $params == array_values($params); |
278 | - foreach($params as $k=>$v) { |
|
278 | + foreach ($params as $k=>$v) { |
|
279 | 279 | if (is_object($v)) { |
280 | 280 | if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s'); |
281 | 281 | else continue; |
282 | 282 | } |
283 | - elseif (is_string($v)) $v="'$v'"; |
|
284 | - elseif ($v === null) $v='NULL'; |
|
283 | + elseif (is_string($v)) $v = "'$v'"; |
|
284 | + elseif ($v === null) $v = 'NULL'; |
|
285 | 285 | elseif (is_array($v)) $v = implode(',', $v); |
286 | 286 | |
287 | 287 | if ($indexed) { |
288 | 288 | $sql_string = preg_replace('/\?/', $v, $sql_string, 1); |
289 | 289 | } |
290 | 290 | else { |
291 | - if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out |
|
292 | - $sql_string = str_replace($k,$v,$sql_string); |
|
291 | + if ($k[0] != ':') $k = ':' . $k; //add leading colon if it was left out |
|
292 | + $sql_string = str_replace($k, $v, $sql_string); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | } |
@@ -277,18 +277,26 @@ |
||
277 | 277 | $indexed = $params == array_values($params); |
278 | 278 | foreach($params as $k=>$v) { |
279 | 279 | if (is_object($v)) { |
280 | - if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s'); |
|
281 | - else continue; |
|
280 | + if ($v instanceof \DateTime) { |
|
281 | + $v = $v->format('Y-m-d H:i:s'); |
|
282 | + } else { |
|
283 | + continue; |
|
284 | + } |
|
285 | + } elseif (is_string($v)) { |
|
286 | + $v="'$v'"; |
|
287 | + } elseif ($v === null) { |
|
288 | + $v='NULL'; |
|
289 | + } elseif (is_array($v)) { |
|
290 | + $v = implode(',', $v); |
|
282 | 291 | } |
283 | - elseif (is_string($v)) $v="'$v'"; |
|
284 | - elseif ($v === null) $v='NULL'; |
|
285 | - elseif (is_array($v)) $v = implode(',', $v); |
|
286 | 292 | |
287 | 293 | if ($indexed) { |
288 | 294 | $sql_string = preg_replace('/\?/', $v, $sql_string, 1); |
289 | - } |
|
290 | - else { |
|
291 | - if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out |
|
295 | + } else { |
|
296 | + if ($k[0] != ':') { |
|
297 | + $k = ':'.$k; |
|
298 | + } |
|
299 | + //add leading colon if it was left out |
|
292 | 300 | $sql_string = str_replace($k,$v,$sql_string); |
293 | 301 | } |
294 | 302 | } |