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

TokenFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 0
cbo 6
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C buildFromHtml() 0 29 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