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

AbstractToken   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 51.61%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 17
c 3
b 0
f 1
lcom 1
cbo 0
dl 0
loc 96
ccs 16
cts 31
cp 0.5161
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getThrowOnError() 0 4 1
A getType() 0 4 1
A isAttribute() 0 4 1
A isCDATA() 0 4 1
A isComment() 0 4 1
A isDocType() 0 4 1
A isElement() 0 4 1
A isText() 0 4 1
B isValidType() 0 9 6
A getParent() 0 4 1
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