Token::getLiteral()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * This file is part of NACL.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2019 Nuglif (2018) Inc.
9
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
10
 * @author    Pierrick Charron <[email protected]>
11
 * @author    Charle Demers <[email protected]>
12
 */
13
14
declare(strict_types=1);
15
16
namespace Nuglif\Nacl;
17
18
class Token
19
{
20
    public const T_NAME         = 256;
21
    public const T_NUM          = 257;
22
    public const T_STRING       = 258;
23
    public const T_BOOL         = 259;
24
    public const T_NULL         = 260;
25
    public const T_ENCAPSED_VAR = 261;
26
    public const T_VAR          = 262;
27
    public const T_END_STR      = 263;
28
    public const T_EOF          = -1;
29
30
    public int|string $type;
31
    public mixed $value;
32
33 589
    public function __construct(int|string $type, mixed $value)
34
    {
35 589
        $this->type  = $type;
36 589
        $this->value = $value;
37
    }
38
39 3
    public static function getLiteral(int|string $type): string
40
    {
41 3
        $refClass = new \ReflectionClass(self::class);
42 3
        $names    = array_flip($refClass->getConstants());
43
44 3
        if (isset($names[$type])) {
45 2
            return $names[$type];
46
        }
47
48
        assert(is_string($type));
49 1
        return $type;
50
    }
51
}
52