| Conditions | 14 |
| Paths | 80 |
| Total Lines | 35 |
| Code Lines | 19 |
| 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 |
||
| 13 | function blockStringValue(string $rawString): string |
||
| 14 | { |
||
| 15 | $lines = \preg_split("/\r\n|[\n\r]/", $rawString); |
||
| 16 | $lines = false === $lines ? [] : $lines; |
||
| 17 | $lineCount = \count($lines); |
||
| 18 | $commonIndent = null; |
||
| 19 | |||
| 20 | for ($i = 1; $i < $lineCount; $i++) { |
||
| 21 | $line = $lines[$i]; |
||
| 22 | $indent = leadingWhitespace($line); |
||
| 23 | |||
| 24 | if ($indent < \mb_strlen($line) && (null === $commonIndent || $indent < $commonIndent)) { |
||
| 25 | $commonIndent = $indent; |
||
| 26 | |||
| 27 | if ($commonIndent === 0) { |
||
| 28 | break; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | if (null !== $commonIndent && $commonIndent > 0) { |
||
| 34 | for ($i = 1; $i < $lineCount; $i++) { |
||
| 35 | $lines[$i] = sliceString($lines[$i], $commonIndent); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | while (\count($lines) > 0 && isBlank($lines[0])) { |
||
| 40 | \array_shift($lines); |
||
| 41 | } |
||
| 42 | |||
| 43 | while (($lineCount = \count($lines)) > 0 && isBlank($lines[$lineCount - 1])) { |
||
| 44 | \array_pop($lines); |
||
| 45 | } |
||
| 46 | |||
| 47 | return \implode("\n", $lines); |
||
| 48 | } |
||
| 74 |