Conditions | 26 |
Paths | 112 |
Total Lines | 129 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
224 | public function update(Array $set, Array $where) |
||
225 | { |
||
226 | $parsed_set = []; |
||
227 | |||
228 | if (!count($set)) |
||
229 | throw new \LogicException("You cannot update rows without SET clause"); |
||
230 | |||
231 | if (!count($where)) |
||
232 | throw new SecurityException("You cannot update rows without WHERE clause!"); |
||
|
|||
233 | |||
234 | $bind_values = []; |
||
235 | |||
236 | $driver = $this->getDriver()->getDriverName(); |
||
237 | |||
238 | $k = 0; |
||
239 | |||
240 | foreach ($set as $key => $value) |
||
241 | { |
||
242 | $k++; |
||
243 | |||
244 | if (is_null($value)) |
||
245 | $parsed_set[] = "$key = NULL"; |
||
246 | elseif ($value instanceof SQLFunction) |
||
247 | $parsed_set[] = "$key = " . $value->getStatement(); |
||
248 | elseif (is_array($value)) |
||
249 | { |
||
250 | $parsed_in = []; |
||
251 | |||
252 | foreach ($value as $in_value) |
||
253 | { |
||
254 | switch ($driver) |
||
255 | { |
||
256 | case 'Oci8': |
||
257 | |||
258 | # [POSSIBLE BUG] - To Future revision (What about non-string values ?) |
||
259 | if (is_string($in_value)) |
||
260 | $parsed_in[] = ":$k"; |
||
261 | |||
262 | $bind_values[":$k"] = $in_value; |
||
263 | break; |
||
264 | |||
265 | case 'Mysqli' || 'Sqlsrv': |
||
266 | $parsed_in[] = "?"; |
||
267 | $bind_values[] = $in_value; |
||
268 | break; |
||
269 | } |
||
270 | |||
271 | $k++; |
||
272 | } |
||
273 | |||
274 | $parsed_set[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
||
275 | } |
||
276 | else |
||
277 | { |
||
278 | switch ($driver) |
||
279 | { |
||
280 | case 'Oci8': |
||
281 | $parsed_set[] = "$key = :$k"; |
||
282 | $bind_values[":$k"] = $value; |
||
283 | break; |
||
284 | |||
285 | case 'Mysqli' || 'Sqlsrv': |
||
286 | $parsed_set[] = "$key = ?"; |
||
287 | $bind_values[] = $value; |
||
288 | break; |
||
289 | } |
||
290 | } |
||
291 | } |
||
292 | |||
293 | $parsed_set = implode(",\r\n\t", $parsed_set); |
||
294 | |||
295 | $parsed_where = []; |
||
296 | |||
297 | foreach ($where as $key => $value) |
||
298 | { |
||
299 | $k++; |
||
300 | |||
301 | if (is_null($value)) |
||
302 | $parsed_where[] = "$key IS NULL"; |
||
303 | elseif ($value instanceof SQLFunction) |
||
304 | $parsed_where[] = "$key = " . $value->getStatement(); |
||
305 | elseif (is_array($value)) |
||
306 | { |
||
307 | $parsed_in = []; |
||
308 | |||
309 | foreach ($value as $in_value) |
||
310 | { |
||
311 | switch ($driver) |
||
312 | { |
||
313 | case 'Oci8': |
||
314 | $parsed_in[] = ":$k"; |
||
315 | $bind_values[":$k"] = $in_value; |
||
316 | break; |
||
317 | |||
318 | case 'Mysqli' || 'Sqlsrv': |
||
319 | $parsed_in[] = "?"; |
||
320 | $bind_values[] = $in_value; |
||
321 | break; |
||
322 | } |
||
323 | |||
324 | $k++; |
||
325 | } |
||
326 | |||
327 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
||
328 | } |
||
329 | else |
||
330 | { |
||
331 | switch ($driver) |
||
332 | { |
||
333 | case 'Oci8': |
||
334 | $parsed_where[] = "$key = :$k"; |
||
335 | $bind_values[":$k"] = $value; |
||
336 | break; |
||
337 | |||
338 | case 'Mysqli' || 'Sqlsrv': |
||
339 | $parsed_where[] = "$key = ?"; |
||
340 | $bind_values[] = $value; |
||
341 | break; |
||
342 | } |
||
343 | } |
||
344 | } |
||
345 | |||
346 | $parsed_where = implode(" AND\r\n\t", $parsed_where); |
||
347 | |||
348 | $table = $this->entity->getTableName(); |
||
349 | |||
350 | $sql = "UPDATE {$table} \r\nSET \r\n\t$parsed_set \r\nWHERE \r\n\t$parsed_where"; |
||
351 | |||
352 | return $this->getDriver()->getDb()->execute($sql, $bind_values); |
||
353 | } |
||
437 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths