Conditions | 5 |
Paths | 8 |
Total Lines | 33 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 5 |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
17 | 17 | public function parse($html) |
|
18 | { |
||
19 | // Collapse whitespace before TEXT. |
||
20 | 17 | $startingWhitespace = ''; |
|
21 | 17 | if (preg_match("/(^\s)/", $html) === 1) { |
|
22 | 5 | $startingWhitespace = ' '; |
|
23 | 5 | } |
|
24 | |||
25 | 17 | $posOfNextElement = mb_strpos($html, '<'); |
|
26 | 17 | if ($posOfNextElement === false) { |
|
27 | 3 | $this->value = $startingWhitespace . trim($html); |
|
28 | |||
29 | 3 | return ''; |
|
30 | } |
||
31 | |||
32 | // Find full length of TEXT. |
||
33 | 14 | $text = mb_substr($html, 0, $posOfNextElement); |
|
34 | 14 | if (trim($text) == '') { |
|
35 | 2 | $this->value = ' '; |
|
36 | |||
37 | 2 | return mb_substr($html, $posOfNextElement); |
|
38 | } |
||
39 | |||
40 | // Collapse whitespace after TEXT. |
||
41 | 13 | $endingWhitespace = ''; |
|
42 | 13 | if (preg_match("/(\s$)/", $text) === 1) { |
|
43 | 5 | $endingWhitespace = ' '; |
|
44 | 5 | } |
|
45 | |||
46 | 13 | $this->value = $startingWhitespace . trim($text) . $endingWhitespace; |
|
47 | |||
48 | 13 | return mb_substr($html, $posOfNextElement); |
|
49 | } |
||
50 | |||
70 |