| Conditions | 4 |
| Paths | 5 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 36 | public static function buildFromHtml(string $html, Token $parent = null, bool $throwOnError = true) |
|
| 21 | { |
||
| 22 | $matchCriteria = array( |
||
| 23 | 36 | 'Php' => "/^\s*<\?(php)?\s/i", |
|
| 24 | 'Comment' => "/^\s*<!--/", |
||
| 25 | 'CData' => "/^\s*<!\[CDATA\[/", |
||
| 26 | 'DocType' => "/^\s*<!DOCTYPE /i", |
||
| 27 | 'Element' => "/^\s*<[a-z]/i", |
||
| 28 | 'Text' => "/^[^<]/" |
||
| 29 | ); |
||
| 30 | 36 | foreach ($matchCriteria as $className => $regex) { |
|
| 31 | 36 | if (preg_match($regex, $html) === 1) { |
|
| 32 | 34 | $fullClassName = "Kevintweber\\HtmlTokenizer\\Tokens\\" . $className; |
|
| 33 | |||
| 34 | 36 | return new $fullClassName($parent, $throwOnError); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | // Error condition |
||
| 39 | 6 | if ($throwOnError) { |
|
| 40 | 2 | throw new TokenMatchingException(); |
|
| 41 | } |
||
| 42 | 4 | } |
|
| 43 | } |
||
| 44 |