Passed
Push — master ( e44dc3...5dec7d )
by Kirill
07:30
created

TokenResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * This file is part of Railt 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\Compiler\Reader\Resolver;
11
12
use Railt\Io\Readable;
13
use Railt\Lexer\TokenInterface;
14
15
/**
16
 * Class TokenResolver
17
 */
18
class TokenResolver implements ResolverInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    private $tokens = [];
24
25
    /**
26
     * @var array
27
     */
28
    private $groups = [];
29
30
    /**
31
     * @param Readable $readable
32
     * @param TokenInterface $token
33
     */
34
    public function resolve(Readable $readable, TokenInterface $token): void
35
    {
36
        $this->tokens[$token->value(1)] = $token->value(2);
37
38
        if ($token->value(3)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $token->value(3) of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
39
            $this->groups[$token->value(1)] = $token->value(3);
40
        }
41
    }
42
}
43