Php   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 22 3
A toArray() 0 9 1
1
<?php
2
3
namespace Kevintweber\HtmlTokenizer\Tokens;
4
5
class Php extends AbstractToken
6
{
7 9
    public function __construct(Token $parent = null, bool $throwOnError = true)
8
    {
9 9
        parent::__construct(Token::PHP, $parent, $throwOnError);
10 9
    }
11
12 7
    public function parse(string $html) : string
13
    {
14 7
        $html = ltrim($html);
15 7
        $this->setTokenPosition($html);
16
17
        // Parse token.
18 7
        $startPos = 3;
19 7
        if (mb_substr(mb_strtolower($html), 0, 5) === '<?php') {
20 7
            $startPos = 6;
21
        }
22
23 7
        $posOfEndOfPhp = mb_strpos($html, '?>');
24 7
        if ($posOfEndOfPhp === false) {
25 1
            $this->value = trim(mb_substr($html, $startPos));
26
27 1
            return '';
28
        }
29
30 6
        $this->value = trim(mb_substr($html, $startPos, $posOfEndOfPhp - $startPos - 1));
31
32 6
        return mb_substr($html, $posOfEndOfPhp + 2);
33
    }
34
35 2
    public function toArray() : array
36
    {
37
        return array(
38 2
            'type' => 'php',
39 2
            'value' => $this->value,
40 2
            'line' => $this->getLine(),
41 2
            'position' => $this->getPosition()
42
        );
43
    }
44
}
45