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

Text::isMatch()   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 1
crap 1
1
<?php
2
3
namespace Kevintweber\HtmlTokenizer\Tokens;
4
5
class Text extends AbstractToken
6
{
7
    /** @var string */
8
    private $value;
9
10 15
    public function __construct(Token $parent = null, $throwOnError = false)
11
    {
12 15
        parent::__construct(Token::TEXT, $parent, $throwOnError);
13
14 15
        $this->value = null;
15 15
    }
16
17 13
    public function parse($html)
18
    {
19 13
        $posOfNextElement = strpos($html, '<');
20 13
        if ($posOfNextElement === false) {
21 3
            $this->value = $html;
22
23 3
            return '';
24
        }
25
26 10
        $this->value = trim(substr($html, 0, $posOfNextElement));
27
28 10
        return substr($html, $posOfNextElement);
29
    }
30
31
    /**
32
     * Getter for 'value'.
33
     *
34
     * @return string
35
     */
36 4
    public function getValue()
37
    {
38 4
        return $this->value;
39
    }
40
41 5
    public function toArray()
42
    {
43
        return array(
44 5
            'type' => 'text',
45 5
            'value' => $this->value
46 5
        );
47
    }
48
}
49
50