Completed
Push — master ( b6caf4...1dc2c9 )
by Kevin
02:09
created

AbstractToken::isElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Kevintweber\HtmlTokenizer\Tokens;
4
5
abstract class AbstractToken implements Token
6
{
7
    /** @var null|Token */
8
    private $parent;
9
10
    /** @var boolean */
11
    private $throwOnError;
12
13
    /** @var string */
14
    private $type;
15
16
    /**
17
     * Constructor
18
     */
19 57
    public function __construct($type, Token $parent = null, $throwOnError = false)
20
    {
21 57
        if (!$this->isValidType($type)) {
22
            throw new \InvalidArgumentException('Invalid type: ' . $type);
23
        }
24
25 57
        $this->parent = $parent;
26 57
        $this->throwOnError = (boolean) $throwOnError;
27 57
        $this->type = $type;
28 57
    }
29
30
    /**
31
     * Getter for 'parent'.
32
     *
33
     * @return Token
34
     */
35 1
    public function getParent()
36
    {
37 1
        return $this->parent;
38
    }
39
40
    /**
41
     * Getter for 'throwOnError'.
42
     *
43
     * @return boolean
44
     */
45 15
    protected function getThrowOnError()
46
    {
47 15
        return $this->throwOnError;
48
    }
49
50
    /**
51
     * Getter for 'type'.
52
     *
53
     * @return string
54
     */
55
    public function getType()
56
    {
57
        return $this->type;
58
    }
59
60
61
    public function isAttribute()
62
    {
63
        return $this->type === Token::ATTRIBUTE;
64
    }
65
66
    public function isCDATA()
67
    {
68
        return $this->type === Token::CDATA;
69
    }
70
71
    public function isComment()
72
    {
73
        return $this->type === Token::COMMENT;
74
    }
75
76
    public function isDocType()
77
    {
78
        return $this->type === Token::DOCTYPE;
79
    }
80
81
    public function isElement()
82
    {
83
        return $this->type === Token::ELEMENT;
84
    }
85
86
    public function isText()
87
    {
88
        return $this->type === Token::TEXT;
89
    }
90
91 57
    protected function isValidType($type)
92
    {
93
        return $type === Token::ATTRIBUTE
94 57
            || $type === Token::CDATA
95 57
            || $type === Token::COMMENT
96 50
            || $type === Token::DOCTYPE
97 39
            || $type === Token::ELEMENT
98 57
            || $type === Token::TEXT;
99
    }
100
}
101