Conditions | 12 |
Paths | 26 |
Total Lines | 67 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 156 |
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 |
||
30 | public function toString(array $config, $header = null) |
||
31 | { |
||
32 | $ini = !empty($header) ? $header . PHP_EOL : ''; |
||
33 | |||
34 | uasort($config, function ($first, $second) { |
||
35 | if (is_array($first)) { |
||
36 | return 1; |
||
37 | } |
||
38 | |||
39 | if (is_array($second)) |
||
40 | { |
||
41 | return -1; |
||
42 | } |
||
43 | |||
44 | return 0; |
||
45 | }); |
||
46 | |||
47 | $names = array_keys($config); |
||
48 | |||
49 | foreach ($names as $name) |
||
50 | { |
||
51 | $section = $config[$name]; |
||
52 | |||
53 | if (!is_array($section)) |
||
54 | { |
||
55 | $ini .= $name . ' = ' . $this->encodeValue($section) . PHP_EOL; |
||
56 | continue; |
||
57 | } |
||
58 | |||
59 | if (empty($section)) |
||
60 | { |
||
61 | continue; |
||
62 | } |
||
63 | |||
64 | if (!empty($ini)) |
||
65 | { |
||
66 | $ini .= PHP_EOL; |
||
67 | } |
||
68 | |||
69 | $ini .= "[$name]" . PHP_EOL; |
||
70 | |||
71 | foreach ($section as $option => $value) |
||
72 | { |
||
73 | if (is_numeric($option)) |
||
74 | { |
||
75 | $option = $name; |
||
76 | $value = (array)$value; |
||
77 | } |
||
78 | |||
79 | if (is_array($value)) |
||
80 | { |
||
81 | foreach ($value as $key => $currentValue) |
||
82 | { |
||
83 | $ini .= $option . '[' . $key . '] = ' . $this->encodeValue($currentValue) . PHP_EOL; |
||
84 | } |
||
85 | } |
||
86 | else |
||
87 | { |
||
88 | $ini .= $option . ' = ' . $this->encodeValue($value) . PHP_EOL; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | $ini .= "\n"; |
||
93 | } |
||
94 | |||
95 | return $ini; |
||
96 | } |
||
97 | |||
119 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.