BaseToken::getBytes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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