Conditions | 8 |
Paths | 9 |
Total Lines | 33 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | public function split($text, $numSymbols) |
||
8 | { |
||
9 | $lines = []; |
||
10 | $char = 0; |
||
11 | $lastPos = 0; |
||
12 | $goodChar = 0; |
||
13 | |||
14 | for ($i = 0; $i < mb_strlen($text); $i++) { |
||
15 | $char++; |
||
16 | |||
17 | if (mb_substr($text, $i, 1) == ' ') { |
||
18 | $goodChar = $i; |
||
19 | } |
||
20 | |||
21 | if ($char > $numSymbols) { |
||
22 | $lines[] = trim(mb_substr($text, $lastPos, $goodChar - $lastPos)); |
||
23 | $char = 0; |
||
24 | $lastPos = $goodChar; |
||
25 | } elseif (mb_substr($text, $i, 2) == '. ' && ($goodChar - $lastPos > 5)) { |
||
26 | $goodChar = $i + 1; |
||
27 | $lines[] = trim(mb_substr($text, $lastPos, $goodChar - $lastPos)); |
||
28 | $char = 0; |
||
29 | $lastPos = $goodChar; |
||
30 | } elseif (mb_substr($text, $i, 2) == '! ' && ($goodChar - $lastPos > 5)) { |
||
31 | $goodChar = $i + 1; |
||
32 | $lines[] = trim(mb_substr($text, $lastPos, $goodChar - $lastPos)); |
||
33 | $char = 0; |
||
34 | $lastPos = $goodChar; |
||
35 | } |
||
36 | } |
||
37 | $lines[] = trim(mb_substr($text, $lastPos, $lastPos + $char)); |
||
38 | return $lines; |
||
39 | } |
||
40 | } |
||
41 |