Conditions | 10 |
Paths | 1 |
Total Lines | 30 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
70 | private function generateArguments(array $arguments) |
||
71 | { |
||
72 | return array_map(function (Node\ArgumentNode $argument) { |
||
73 | $php = ''; |
||
74 | |||
75 | if ($hint = $argument->getTypeHint()) { |
||
76 | switch ($hint) { |
||
77 | case 'array': |
||
78 | case 'callable': |
||
79 | case 'string': |
||
80 | case 'int': |
||
81 | case 'float': |
||
82 | case 'bool': |
||
83 | $php .= $hint; |
||
84 | break; |
||
85 | |||
86 | default: |
||
87 | $php .= '\\'.$hint; |
||
88 | } |
||
89 | } |
||
90 | |||
91 | $php .= ' '.($argument->isPassedByReference() ? '&' : '').'$'.$argument->getName(); |
||
92 | |||
93 | if ($argument->isOptional()) { |
||
94 | $php .= ' = '.var_export($argument->getDefault(), true); |
||
95 | } |
||
96 | |||
97 | return $php; |
||
98 | }, $arguments); |
||
99 | } |
||
100 | } |
||
101 |