| 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 |
||
| 87 | private function compactAnnotations(string $docblock): string |
||
| 88 | { |
||
| 89 | $annotations = []; |
||
| 90 | $index = -1; |
||
| 91 | $inside = 0; |
||
| 92 | $tokens = $this->tokenizer->parse($docblock); |
||
| 93 | |||
| 94 | if (empty($tokens)) { |
||
| 95 | return str_repeat("\n", substr_count($docblock, "\n")); |
||
| 96 | } |
||
| 97 | |||
| 98 | foreach ($tokens as $token) { |
||
| 99 | if ((0 === $inside) && (DocLexer::T_AT === $token[0])) { |
||
| 100 | ++$index; |
||
| 101 | } elseif (DocLexer::T_OPEN_PARENTHESIS === $token[0]) { |
||
| 102 | ++$inside; |
||
| 103 | } elseif (DocLexer::T_CLOSE_PARENTHESIS === $token[0]) { |
||
| 104 | --$inside; |
||
| 105 | } |
||
| 106 | |||
| 107 | if (!isset($annotations[$index])) { |
||
| 108 | $annotations[$index] = []; |
||
| 109 | } |
||
| 110 | |||
| 111 | $annotations[$index][] = $token; |
||
| 112 | } |
||
| 113 | |||
| 114 | $breaks = substr_count($docblock, "\n"); |
||
| 115 | $docblock = '/**'; |
||
| 116 | |||
| 117 | foreach ($annotations as $annotation) { |
||
| 118 | $annotation = new Tokens($annotation); |
||
| 119 | $docblock .= "\n".$this->converter->convert($annotation); |
||
| 120 | } |
||
| 121 | |||
| 122 | $breaks -= count($annotations); |
||
| 123 | |||
| 124 | if ($breaks > 0) { |
||
| 125 | $docblock .= str_repeat("\n", $breaks - 1); |
||
| 126 | $docblock .= "\n*/"; |
||
| 127 | } else { |
||
| 128 | $docblock .= ' */'; |
||
| 129 | } |
||
| 130 | |||
| 131 | return $docblock; |
||
| 132 | } |
||
| 134 |