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

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