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

TokenResolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 25
c 0
b 0
f 0
ccs 0
cts 7
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 8 2
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