Conditions | 11 |
Paths | 12 |
Total Lines | 43 |
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 |
||
33 | private static function innerExportValues($item, bool $first): string |
||
34 | { |
||
35 | if ($item === null) { |
||
36 | return 'null'; |
||
37 | } |
||
38 | if (is_string($item)) { |
||
39 | return '"'.str_replace('"', '""', $item).'"'; |
||
40 | } |
||
41 | if (is_numeric($item)) { |
||
42 | return $item; |
||
43 | } |
||
44 | if (is_bool($item)) { |
||
45 | return $item ? 'true' : 'false'; |
||
46 | } |
||
47 | if (is_array($item)) { |
||
48 | if (self::isAssoc($item)) { |
||
49 | if ($first) { |
||
50 | array_walk($item, function(&$value, $key) { |
||
51 | $value = $key.' = '.self::innerExportValues($value, false); |
||
52 | }); |
||
53 | } else { |
||
54 | array_walk($item, function(&$value, $key) { |
||
55 | $value = '"'.addslashes($key).'":'.self::innerExportValues($value, false); |
||
56 | }); |
||
57 | } |
||
58 | $result = implode(', ', $item); |
||
59 | if (!$first) { |
||
60 | $result = '{'.$result.'}'; |
||
61 | } |
||
62 | return $result; |
||
63 | } else { |
||
64 | array_walk($item, function(&$value, $key) { |
||
|
|||
65 | $value = self::innerExportValues($value, false); |
||
66 | }); |
||
67 | $result = implode(', ', $item); |
||
68 | if (!$first) { |
||
69 | $result = '{'.$result.'}'; |
||
70 | } |
||
71 | return $result; |
||
72 | } |
||
73 | } |
||
74 | throw new \RuntimeException('Cannot serialize value in Doctrine annotation.'); |
||
75 | } |
||
76 | |||
82 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.