Completed
Push — master ( fd987e...4f1c16 )
by Kevin
02:24
created

Php   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

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