BaseToken   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 38
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBytes() 0 8 2
A getLength() 0 8 2
1
<?php
2
/**
3
 * This file is part of Lexer package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Lexer\Result;
11
12
use Railt\Lexer\Result\Common\Renderable;
13
use Railt\Lexer\TokenInterface;
14
15
/**
16
 * Class BaseToken
17
 */
18
abstract class BaseToken implements TokenInterface
19
{
20
    use Renderable;
21
22
    /**
23
     * @var int|null
24
     */
25
    private $length;
26
27
    /**
28
     * @var int|null
29
     */
30
    private $bytes;
31
32
    /**
33
     * @return int
34
     */
35 6
    public function getBytes(): int
36
    {
37 6
        if ($this->bytes === null) {
38 6
            $this->bytes = \strlen($this->getValue());
39
        }
40
41 6
        return $this->bytes;
42
    }
43
44
    /**
45
     * @return int
46
     */
47 1
    public function getLength(): int
48
    {
49 1
        if ($this->length === null) {
50 1
            $this->length = \mb_strlen($this->getValue());
51
        }
52
53 1
        return $this->length;
54
    }
55
}
56