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