Conditions | 10 |
Paths | 17 |
Total Lines | 25 |
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 |
||
91 | protected function generateProposedFileFromTokens(array $tokens, int $lineNumber, string $unexpectedChar): string |
||
92 | { |
||
93 | $reverseTokens = array_reverse($tokens); |
||
94 | $output = []; |
||
95 | $insertSemicolon = false; |
||
96 | $line = 0; |
||
97 | foreach ($reverseTokens as $token) { |
||
98 | $char = isset($token[1]) ? $token[1] : $token; |
||
99 | |||
100 | $output[] = $char; |
||
101 | |||
102 | if (isset($token[2])) { |
||
103 | $line = $token[2]; |
||
104 | } |
||
105 | if (is_string($token) && $line == $lineNumber && $char == $unexpectedChar) { |
||
106 | $insertSemicolon = true; |
||
107 | } |
||
108 | if ($insertSemicolon && isset($token[0]) && $token[0] == T_WHITESPACE) { |
||
109 | $insertSemicolon = false; |
||
110 | $output[] = ';'; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | return implode('', array_reverse($output)); |
||
115 | } |
||
116 | } |
||
117 |