Conditions | 11 |
Paths | 1 |
Total Lines | 36 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
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 |
||
72 | private function generateArguments(array $arguments) |
||
73 | { |
||
74 | return array_map(function (Node\ArgumentNode $argument) { |
||
75 | $php = ''; |
||
76 | |||
77 | if ($hint = $argument->getTypeHint()) { |
||
78 | switch ($hint) { |
||
79 | case 'array': |
||
80 | case 'callable': |
||
81 | $php .= $hint; |
||
82 | break; |
||
83 | |||
84 | case 'string': |
||
85 | case 'int': |
||
86 | case 'float': |
||
87 | case 'bool': |
||
88 | if (version_compare(PHP_VERSION, '7.0', '>=')) { |
||
89 | $php .= $hint; |
||
90 | break; |
||
91 | } |
||
92 | // Fall-through to default case for PHP 5.x |
||
93 | |||
94 | default: |
||
95 | $php .= '\\'.$hint; |
||
96 | } |
||
97 | } |
||
98 | |||
99 | $php .= ' '.($argument->isPassedByReference() ? '&' : '').'$'.$argument->getName(); |
||
100 | |||
101 | if ($argument->isOptional()) { |
||
102 | $php .= ' = '.var_export($argument->getDefault(), true); |
||
103 | } |
||
104 | |||
105 | return $php; |
||
106 | }, $arguments); |
||
107 | } |
||
108 | } |
||
109 |