| Conditions | 26 |
| Paths | 112 |
| Total Lines | 132 |
| Code Lines | 77 |
| 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 |
||
| 235 | public function update(Array $set, Array $where) |
||
| 236 | { |
||
| 237 | $parsed_set = []; |
||
| 238 | |||
| 239 | if (!count($set)) |
||
| 240 | throw new \LogicException("You cannot update rows without SET clause"); |
||
| 241 | |||
| 242 | if (!count($where)) |
||
| 243 | throw new SecurityException("You cannot update rows without WHERE clause!"); |
||
|
|
|||
| 244 | |||
| 245 | $bind_values = []; |
||
| 246 | |||
| 247 | $driver = $this->getDb()->getDriverName(); |
||
| 248 | |||
| 249 | $k = 0; |
||
| 250 | |||
| 251 | foreach ($set as $key => $value) |
||
| 252 | { |
||
| 253 | $k++; |
||
| 254 | |||
| 255 | if (is_null($value)) |
||
| 256 | $parsed_set[] = "$key = NULL"; |
||
| 257 | elseif ($value instanceof SQLFunction) |
||
| 258 | $parsed_set[] = "$key = " . $value->getStatement(); |
||
| 259 | elseif (is_array($value)) |
||
| 260 | { |
||
| 261 | $parsed_in = []; |
||
| 262 | |||
| 263 | foreach ($value as $in_value) |
||
| 264 | { |
||
| 265 | switch ($driver) |
||
| 266 | { |
||
| 267 | case 'Oci8': |
||
| 268 | |||
| 269 | # [POSSIBLE BUG] - To Future revision (What about non-string values ?) |
||
| 270 | if (is_string($in_value)) |
||
| 271 | $parsed_in[] = ":$k"; |
||
| 272 | |||
| 273 | $bind_values[":$k"] = $in_value; |
||
| 274 | break; |
||
| 275 | |||
| 276 | case 'Mysqli' || 'Sqlsrv': |
||
| 277 | $parsed_in[] = "?"; |
||
| 278 | $bind_values[] = $in_value; |
||
| 279 | break; |
||
| 280 | } |
||
| 281 | |||
| 282 | $k++; |
||
| 283 | } |
||
| 284 | |||
| 285 | $parsed_set[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
||
| 286 | } |
||
| 287 | else |
||
| 288 | { |
||
| 289 | switch ($driver) |
||
| 290 | { |
||
| 291 | case 'Oci8': |
||
| 292 | $parsed_set[] = "$key = :$k"; |
||
| 293 | $bind_values[":$k"] = $value; |
||
| 294 | break; |
||
| 295 | |||
| 296 | case 'Mysqli' || 'Sqlsrv': |
||
| 297 | $parsed_set[] = "$key = ?"; |
||
| 298 | $bind_values[] = $value; |
||
| 299 | break; |
||
| 300 | } |
||
| 301 | } |
||
| 302 | } |
||
| 303 | |||
| 304 | $parsed_set = implode(",\r\n\t", $parsed_set); |
||
| 305 | |||
| 306 | $parsed_where = []; |
||
| 307 | |||
| 308 | foreach ($where as $key => $value) |
||
| 309 | { |
||
| 310 | $k++; |
||
| 311 | |||
| 312 | if (is_null($value)) |
||
| 313 | $parsed_where[] = "$key IS NULL"; |
||
| 314 | elseif ($value instanceof SQLFunction) |
||
| 315 | $parsed_where[] = "$key = " . $value->getStatement(); |
||
| 316 | elseif (is_array($value)) |
||
| 317 | { |
||
| 318 | $parsed_in = []; |
||
| 319 | |||
| 320 | foreach ($value as $in_value) |
||
| 321 | { |
||
| 322 | switch ($driver) |
||
| 323 | { |
||
| 324 | case 'Oci8': |
||
| 325 | $parsed_in[] = ":$k"; |
||
| 326 | $bind_values[":$k"] = $in_value; |
||
| 327 | break; |
||
| 328 | |||
| 329 | case 'Mysqli' || 'Sqlsrv': |
||
| 330 | $parsed_in[] = "?"; |
||
| 331 | $bind_values[] = $in_value; |
||
| 332 | break; |
||
| 333 | } |
||
| 334 | |||
| 335 | $k++; |
||
| 336 | } |
||
| 337 | |||
| 338 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
||
| 339 | } |
||
| 340 | else |
||
| 341 | { |
||
| 342 | switch ($driver) |
||
| 343 | { |
||
| 344 | case 'Oci8': |
||
| 345 | $parsed_where[] = "$key = :$k"; |
||
| 346 | $bind_values[":$k"] = $value; |
||
| 347 | break; |
||
| 348 | |||
| 349 | case 'Mysqli' || 'Sqlsrv': |
||
| 350 | $parsed_where[] = "$key = ?"; |
||
| 351 | $bind_values[] = $value; |
||
| 352 | break; |
||
| 353 | } |
||
| 354 | } |
||
| 355 | } |
||
| 356 | |||
| 357 | $parsed_where = implode(" AND\r\n\t", $parsed_where); |
||
| 358 | |||
| 359 | $table = $this->entity->getTableName(); |
||
| 360 | |||
| 361 | $sql = "UPDATE {$table} \r\nSET \r\n\t$parsed_set \r\nWHERE \r\n\t$parsed_where"; |
||
| 362 | |||
| 363 | $this->lastQuery = $sql; |
||
| 364 | $this->lastValues = $bind_values; |
||
| 365 | |||
| 366 | return $this->getDb()->execute($sql, $bind_values); |
||
| 367 | } |
||
| 454 | } |
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