Conditions | 4 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 4 |
Changes | 3 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
9 | 18 | public static function buildFromHtml($html, Token $parent = null, $throwOnError = false) |
|
10 | { |
||
11 | $matchCriteria = array( |
||
12 | 18 | 'Text' => "/^[^<]/", |
|
13 | 18 | 'Element' => "/^<[a-z]/i", |
|
14 | 18 | 'Comment' => "/^<!--/", |
|
15 | 18 | 'CData' => "/^<!\[CDATA\[/", |
|
16 | 'DocType' => "/^<!DOCTYPE /i" |
||
17 | 18 | ); |
|
18 | 18 | foreach ($matchCriteria as $className => $regex) { |
|
19 | 18 | if (preg_match($regex, $html) === 1) { |
|
20 | 15 | $fullClassName = "Kevintweber\\HtmlTokenizer\\Tokens\\" . $className; |
|
21 | |||
22 | 15 | return new $fullClassName($parent, $throwOnError); |
|
23 | } |
||
24 | 10 | } |
|
25 | |||
26 | // Error condition |
||
27 | 4 | if ($throwOnError) { |
|
28 | 1 | throw new TokenMatchingException(); |
|
29 | } |
||
30 | |||
31 | 3 | return false; |
|
32 | } |
||
33 | } |
||
34 |