| Conditions | 13 |
| Paths | 13 |
| Total Lines | 79 |
| Code Lines | 43 |
| 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 |
||
| 72 | protected function compactContent(string $contents): string |
||
| 73 | { |
||
| 74 | $output = ''; |
||
| 75 | $tokens = PhpToken::tokenize($contents); |
||
| 76 | $tokenCount = count($tokens); |
||
| 77 | |||
| 78 | for ($index = 0; $index < $tokenCount; ++$index) { |
||
| 79 | $token = $tokens[$index]; |
||
| 80 | $tokenText = $token->text; |
||
| 81 | |||
| 82 | if ($token->is([T_COMMENT, T_DOC_COMMENT])) { |
||
| 83 | if (str_starts_with($tokenText, '#[')) { |
||
| 84 | // This is, in all likelihood, the start of a PHP >= 8.0 attribute. |
||
| 85 | // Note: $tokens may be updated by reference as well! |
||
| 86 | $retokenized = $this->retokenizeAttribute($tokens, $index); |
||
| 87 | |||
| 88 | if (null !== $retokenized) { |
||
| 89 | array_splice($tokens, $index, 1, $retokenized); |
||
| 90 | $tokenCount = count($tokens); |
||
| 91 | } |
||
| 92 | |||
| 93 | $attributeCloser = self::findAttributeCloser($tokens, $index); |
||
| 94 | |||
| 95 | if (is_int($attributeCloser)) { |
||
| 96 | $output .= '#['; |
||
| 97 | } else { |
||
| 98 | // Turns out this was not an attribute. Treat it as a plain comment. |
||
| 99 | $output .= str_repeat("\n", mb_substr_count($tokenText, "\n")); |
||
| 100 | } |
||
| 101 | } elseif (str_contains($tokenText, '@')) { |
||
| 102 | try { |
||
| 103 | $output .= $this->compactAnnotations($tokenText); |
||
| 104 | } catch (RuntimeException) { |
||
| 105 | $output .= $tokenText; |
||
| 106 | } |
||
| 107 | } else { |
||
| 108 | $output .= str_repeat("\n", mb_substr_count($tokenText, "\n")); |
||
| 109 | } |
||
| 110 | } elseif ($token->is(T_WHITESPACE)) { |
||
| 111 | $whitespace = $tokenText; |
||
| 112 | $previousIndex = ($index - 1); |
||
| 113 | |||
| 114 | // Handle whitespace potentially being split into two tokens after attribute retokenization. |
||
| 115 | $nextToken = $tokens[$index + 1] ?? null; |
||
| 116 | |||
| 117 | if (null !== $nextToken |
||
| 118 | && $nextToken->is(T_WHITESPACE) |
||
| 119 | ) { |
||
| 120 | $whitespace .= $nextToken->text; |
||
| 121 | ++$index; |
||
| 122 | } |
||
| 123 | |||
| 124 | // reduce wide spaces |
||
| 125 | $whitespace = preg_replace('{[ \t]+}', ' ', $whitespace); |
||
| 126 | |||
| 127 | // normalize newlines to \n |
||
| 128 | $whitespace = preg_replace('{(?:\r\n|\r|\n)}', "\n", $whitespace); |
||
| 129 | |||
| 130 | // If the new line was split off from the whitespace token due to it being included in |
||
| 131 | // the previous (comment) token (PHP < 8), remove leading spaces. |
||
| 132 | |||
| 133 | $previousToken = $tokens[$previousIndex]; |
||
| 134 | |||
| 135 | if ($previousToken->is(T_COMMENT) |
||
| 136 | && str_contains($previousToken->text, "\n") |
||
| 137 | ) { |
||
| 138 | $whitespace = ltrim($whitespace, ' '); |
||
| 139 | } |
||
| 140 | |||
| 141 | // trim leading spaces |
||
| 142 | $whitespace = preg_replace('{\n +}', "\n", $whitespace); |
||
| 143 | |||
| 144 | $output .= $whitespace; |
||
| 145 | } else { |
||
| 146 | $output .= $tokenText; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | return $output; |
||
| 151 | } |
||
| 265 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths