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

Text   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 5
c 3
b 0
f 2
lcom 1
cbo 1
dl 0
loc 44
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A parse() 0 13 2
A getValue() 0 4 1
A toArray() 0 7 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