Completed
Push — master ( 49d11e...aa9157 )
by Kevin
02:09
created

TokenFactory::buildFromHtml()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 6.7272
cc 7
eloc 14
nc 7
nop 3
crap 7
1
<?php
2
3
namespace Kevintweber\HtmlTokenizer\Tokens;
4
5
use Kevintweber\HtmlTokenizer\Exceptions\TokenMatchingException;
6
7
class TokenFactory
8
{
9 14
    public static function buildFromHtml($html, Token $parent = null, $throwOnError = false)
10
    {
11 14
        if (Text::isMatch($html)) {
12 8
            return new Text($parent, $throwOnError);
13
        }
14
15 7
        if (Element::isMatch($html)) {
16 1
            return new Element($parent, $throwOnError);
17
        }
18
19 6
        if (Comment::isMatch($html)) {
20 1
            return new Comment($parent, $throwOnError);
21
        }
22
23 5
        if (CData::isMatch($html)) {
24 1
            return new CData($parent, $throwOnError);
25
        }
26
27 4
        if (DocType::isMatch($html)) {
28 1
            return new DocType($parent, $throwOnError);
29
        }
30
31
        // Error condition
32 3
        if ($throwOnError) {
33 1
            throw new TokenMatchingException();
34
        }
35
36 2
        return false;
37
    }
38
}
39