Conditions | 10 |
Paths | 27 |
Total Lines | 30 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 11.3027 |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
27 | public function parseUpdate() |
||
28 | 1 | { |
|
29 | if (!$this->parts['data']) { |
||
30 | 1 | return false; |
|
31 | } |
||
32 | $fields = []; |
||
33 | 1 | foreach ($this->parts['data'] as $data) { |
|
34 | 1 | foreach ($data as $key => $values) { |
|
35 | 1 | if (!is_array($values)) { |
|
36 | 1 | $values = [$values]; |
|
37 | } |
||
38 | $value = $values[0]; |
||
39 | 1 | $quote = isset($values[1]) ? $values[1] : null; |
|
40 | 1 | ||
41 | if ($value === null) { |
||
42 | 1 | $value = 'NULL'; |
|
43 | 1 | } elseif (!is_numeric($value)) { |
|
44 | if (is_null($quote)) { |
||
45 | $quote = true; |
||
46 | 1 | } |
|
47 | if ($quote) { |
||
48 | $value = $this->getManager()->getAdapter()->quote($value); |
||
49 | } |
||
50 | } |
||
51 | 1 | ||
52 | $fields[] = "{$this->protect($key)} = $value"; |
||
53 | } |
||
54 | } |
||
55 | 1 | ||
56 | return implode(", ", $fields); |
||
57 | } |
||
59 |