Test Failed
Push — master ( 3ca5bd...939415 )
by Kirill
02:50
created

BaseToken::getLength()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 2
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
    public function getBytes(): int
36
    {
37
        if ($this->bytes === null) {
38
            $this->bytes = \strlen($this->getValue());
39
        }
40
41
        return $this->bytes;
42
    }
43
44
    /**
45
     * @return int
46
     */
47
    public function getLength(): int
48
    {
49
        if ($this->length === null) {
50
            $this->length = \mb_strlen($this->getValue());
51
        }
52 17
53
        return $this->length;
54 17
    }
55
}
56