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

RuleResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 50
c 0
b 0
f 0
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 6 2
A next() 0 14 3
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\Compiler\Exception\GrammarException;
13
use Railt\Io\Readable;
14
use Railt\Lexer\TokenInterface;
15
16
/**
17
 * Class RuleResolver
18
 */
19
class RuleResolver implements ResolverInterface
20
{
21
    /**
22
     * @var array|string[]
23
     */
24
    private $rules = [];
25
26
    /**
27
     * @var string|null
28
     */
29
    private $current;
30
31
    /**
32
     * @var array|string[]
33
     */
34
    private $keep = [];
35
36
    /**
37
     * @var array|string[]
38
     */
39
    private $delegates = [];
40
41
    public function resolve(Readable $readable, TokenInterface $token): void
42
    {
43
        if ($this->next($readable, $token)) {
44
            return;
45
        }
46
    }
47
48
    /**
49
     * @param Readable $readable
50
     * @param TokenInterface $token
51
     * @return bool
52
     * @throws \Railt\Io\Exception\ExternalFileException
53
     */
54
    private function next(Readable $readable, TokenInterface $token): bool
55
    {
56
        if ($token->name() === 'T_NODE_DEFINITION') {
57
            $this->current = $token->value(1);
58
            return true;
59
        }
60
61
        if ($this->current === null) {
62
            $error = \sprintf('Unprocessed production %s', $token->value(0));
63
            throw (new GrammarException($error))->throwsIn($readable, $token->offset());
64
        }
65
66
        return false;
67
    }
68
}
69