Completed
Push — master ( 15134a...d6e1fc )
by Kevin
02:45
created

AbstractToken::isCDATA()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Kevintweber\HtmlTokenizer\Tokens;
4
5
abstract class AbstractToken implements Token
6
{
7
    /** @var int */
8
    private $depth;
9
10
    /** @var int */
11
    protected $line;
12
13
    /** @var null|Token */
14
    private $parent;
15
16
    /** @var int */
17
    protected $position;
18
19
    /** @var boolean */
20
    private $throwOnError;
21
22
    /** @var string */
23
    private $type;
24
25
    /** @var string */
26
    protected $value;
27
28
    /**
29
     * Constructor
30
     */
31 116
    public function __construct(string $type, Token $parent = null, bool $throwOnError = false)
32
    {
33 116
        if (!$this->isValidType($type)) {
34 1
            throw new \InvalidArgumentException('Invalid type: ' . $type);
35
        }
36
37 115
        $this->depth = 0;
38 115
        if ($parent instanceof Token) {
39 43
            $this->depth = $parent->getDepth() + 1;
40
        }
41
42 115
        $this->line = 0;
43 115
        $this->position = 0;
44 115
        $this->parent = $parent;
45 115
        $this->throwOnError = $throwOnError;
46 115
        $this->type = $type;
47 115
        $this->value = '';
48 115
    }
49
50 43
    public function getDepth() : int
51
    {
52 43
        return $this->depth;
53
    }
54
55
    /**
56
     * Getter for 'line'.
57
     */
58 38
    public function getLine() : int
59
    {
60 38
        return $this->line;
61
    }
62
63 19
    public function isClosingElementImplied(string $html) : bool
64
    {
65 19
        return false;
66
    }
67
68 28
    public function getParent()
69
    {
70 28
        return $this->parent;
71
    }
72
73
    /**
74
     * Getter for 'position'.
75
     */
76 38
    public function getPosition() : int
77
    {
78 38
        return $this->position;
79
    }
80
81
    /**
82
     * Getter for 'throwOnError'.
83
     *
84
     * @return boolean
85
     */
86 38
    protected function getThrowOnError()
87
    {
88 38
        return $this->throwOnError;
89
    }
90
91
    /**
92
     * Getter for 'type'.
93
     *
94
     * @return string
95
     */
96 1
    public function getType() : string
97
    {
98 1
        return $this->type;
99
    }
100
101
    /**
102
     * Getter for "value"
103
     *
104
     * @return string
105
     */
106 50
    public function getValue() : string
107
    {
108 50
        return $this->value;
109
    }
110
111 1
    public function isCDATA() : bool
112
    {
113 1
        return $this->type === Token::CDATA;
114
    }
115
116 1
    public function isComment() : bool
117
    {
118 1
        return $this->type === Token::COMMENT;
119
    }
120
121 1
    public function isDocType() : bool
122
    {
123 1
        return $this->type === Token::DOCTYPE;
124
    }
125
126 1
    public function isElement() : bool
127
    {
128 1
        return $this->type === Token::ELEMENT;
129
    }
130
131 1
    public function isPhp() : bool
132
    {
133 1
        return $this->type === Token::PHP;
134
    }
135
136 23
    public function isText() : bool
137
    {
138 23
        return $this->type === Token::TEXT;
139
    }
140
141 116
    protected function isValidType(string $type) : bool
142
    {
143 116
        return $type === Token::CDATA
144 109
            || $type === Token::COMMENT
145 99
            || $type === Token::DOCTYPE
146 91
            || $type === Token::ELEMENT
147 42
            || $type === Token::PHP
148 116
            || $type === Token::TEXT;
149
    }
150
}
151