| Conditions | 10 |
| Paths | 37 |
| Total Lines | 45 |
| Code Lines | 28 |
| 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 |
||
| 96 | private function compactAnnotations(string $docblock): string |
||
| 97 | { |
||
| 98 | $annotations = []; |
||
| 99 | $index = -1; |
||
| 100 | $inside = 0; |
||
| 101 | $tokens = $this->tokenizer->parse($docblock); |
||
| 102 | |||
| 103 | if (empty($tokens)) { |
||
| 104 | return str_repeat("\n", substr_count($docblock, "\n")); |
||
| 105 | } |
||
| 106 | |||
| 107 | foreach ($tokens as $token) { |
||
| 108 | if ((0 === $inside) && (DocLexer::T_AT === $token[0])) { |
||
| 109 | ++$index; |
||
| 110 | } elseif (DocLexer::T_OPEN_PARENTHESIS === $token[0]) { |
||
| 111 | ++$inside; |
||
| 112 | } elseif (DocLexer::T_CLOSE_PARENTHESIS === $token[0]) { |
||
| 113 | --$inside; |
||
| 114 | } |
||
| 115 | |||
| 116 | if (!isset($annotations[$index])) { |
||
| 117 | $annotations[$index] = []; |
||
| 118 | } |
||
| 119 | |||
| 120 | $annotations[$index][] = $token; |
||
| 121 | } |
||
| 122 | |||
| 123 | $breaks = substr_count($docblock, "\n"); |
||
| 124 | $docblock = '/**'; |
||
| 125 | |||
| 126 | foreach ($annotations as $annotation) { |
||
| 127 | $annotation = new Tokens($annotation); |
||
| 128 | $docblock .= "\n".$this->converter->convert($annotation); |
||
| 129 | } |
||
| 130 | |||
| 131 | $breaks -= count($annotations); |
||
| 132 | |||
| 133 | if ($breaks > 0) { |
||
| 134 | $docblock .= str_repeat("\n", $breaks - 1); |
||
| 135 | $docblock .= "\n*/"; |
||
| 136 | } else { |
||
| 137 | $docblock .= ' */'; |
||
| 138 | } |
||
| 139 | |||
| 140 | return $docblock; |
||
| 141 | } |
||
| 143 |