| Conditions | 4 |
| Paths | 3 |
| Total Lines | 21 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | function descriptionLines(string $description, int $maxLength): array |
||
| 11 | { |
||
| 12 | $lines = []; |
||
| 13 | $rawLines = \explode("\n", $description); |
||
| 14 | $rawLinesCount = \count($rawLines); |
||
| 15 | |||
| 16 | for ($i = 0; $i < $rawLinesCount; $i++) { |
||
| 17 | if ('' === $rawLines[$i]) { |
||
| 18 | $lines[] = $rawLines[$i]; |
||
| 19 | continue; |
||
| 20 | } |
||
| 21 | |||
| 22 | // For > 120 character long lines, cut at space boundaries into sublines |
||
| 23 | // of ~80 chars. |
||
| 24 | $subLines = breakLine($rawLines[$i], $maxLength); |
||
| 25 | for ($j = 0; $j < \count($subLines); $j++) { |
||
|
|
|||
| 26 | $lines[] = $subLines[$j]; |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | return $lines; |
||
| 31 | } |
||
| 69 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: