Completed
Push — master ( 26824d...9bbb30 )
by Kevin
02:15
created

DocType::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Kevintweber\HtmlTokenizer\Tokens;
4
5
use Kevintweber\HtmlTokenizer\Exceptions\ParseException;
6
7
class DocType extends AbstractToken
8
{
9
    /** @var string */
10
    private $value;
11
12 8
    public function __construct(Token $parent = null, $throwOnError = false)
13
    {
14 8
        parent::__construct(Token::DOCTYPE, $parent, $throwOnError);
15
16 8
        $this->value = null;
17 8
    }
18
19 7
    public function parse($html)
20
    {
21 7
        $posOfEndOfDocType = strpos($html, '>');
22 7
        if ($posOfEndOfDocType === false) {
23 2
            if ($this->getThrowOnError()) {
24 1
                throw new ParseException('Invalid DOCTYPE.');
25
            }
26
27 1
            return '';
28
        }
29
30 5
        $this->value = trim(substr($html, 10, $posOfEndOfDocType - 10));
31
32 5
        return trim(substr($html, $posOfEndOfDocType + 1));
33
    }
34
35
    /**
36
     * Getter for 'value'.
37
     *
38
     * @return string
39
     */
40 5
    public function getValue()
41
    {
42 5
        return $this->value;
43
    }
44
45 1
    public function toArray()
46
    {
47
        return array(
48 1
            'type' => 'doctype',
49 1
            'value' => $this->value
50 1
        );
51
    }
52
}
53