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

Comment   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 6
c 3
b 0
f 2
lcom 1
cbo 2
dl 0
loc 46
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A parse() 0 15 3
A getValue() 0 4 1
A toArray() 0 7 1
1
<?php
2
3
namespace Kevintweber\HtmlTokenizer\Tokens;
4
5
use Kevintweber\HtmlTokenizer\Exceptions\ParseException;
6
7
class Comment extends AbstractToken
8
{
9
    /** @var string */
10
    private $value;
11
12 11
    public function __construct(Token $parent = null, $throwOnError = false)
13
    {
14 11
        parent::__construct(Token::COMMENT, $parent, $throwOnError);
15
16 11
        $this->value = null;
17 11
    }
18
19 8
    public function parse($html)
20
    {
21 8
        $posOfEndOfComment = strpos($html, '-->');
22 8
        if ($posOfEndOfComment === false) {
23 2
            if ($this->getThrowOnError()) {
24 1
                throw new ParseException('Invalid comment.');
25
            }
26
27 1
            return '';
28
        }
29
30 6
        $this->value = trim(substr($html, 4, $posOfEndOfComment - 4));
31
32 6
        return trim(substr($html, $posOfEndOfComment + 3));
33
    }
34
35
    /**
36
     * Getter for 'value'.
37
     *
38
     * @return string
39
     */
40 6
    public function getValue()
41
    {
42 6
        return $this->value;
43
    }
44
45 1
    public function toArray()
46
    {
47
        return array(
48 1
            'type' => 'comment',
49 1
            'value' => $this->value
50 1
        );
51
    }
52
}
53
54