Completed
Push — master ( 88ff28...2dc58f )
by Kirill
06:03
created

Runtime   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 58
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getLexer() 0 10 2
A getParser() 0 12 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;
11
use Railt\Compiler\Reader\Resolver\PragmaResolver;
12
use Railt\Compiler\Reader\Resolver\RuleResolver;
13
use Railt\Compiler\Reader\Resolver\TokenResolver;
14
use Railt\Lexer\Driver\NativeStateless;
15
use Railt\Lexer\LexerInterface;
16
use Railt\Parser\Parser;
17
use Railt\Parser\ParserInterface;
18
use Railt\Parser\Rule\Token;
19
20
/**
21
 * Class Runtime
22
 */
23
class Runtime
24
{
25
    /**
26
     * @var RuleResolver
27
     */
28
    private $rules;
29
30
    /**
31
     * @var PragmaResolver
32
     */
33
    private $config;
34
35
    /**
36
     * @var TokenResolver
37
     */
38
    private $tokens;
39
40
    /**
41
     * Runtime constructor.
42
     * @param Result $result
43
     */
44
    public function __construct(Result $result)
45
    {
46
        $this->rules = $result->rulesResolver();
47
        $this->tokens = $result->tokensResolver();
48
        $this->config = $result->pragmasResolver();
49
    }
50
    /**
51
     * @return LexerInterface
52
     */
53
    public function getLexer(): LexerInterface
54
    {
55
        $lexer = new NativeStateless();
56
57
        foreach ($this->tokens->getTokens() as $name => $pcre) {
58
            $lexer->add($name, $pcre, \in_array($name, $this->tokens->getSkip(), true));
59
        }
60
61
        return $lexer;
62
    }
63
64
    /**
65
     * @return ParserInterface
66
     * @throws \InvalidArgumentException
67
     */
68
    public function getParser(): ParserInterface
69
    {
70
        $configs = $this->config->all(PragmaResolver::GROUP_PARSER);
71
72
        $parser = new Parser($this->getLexer(), $this->rules->getParsedRules(), $configs);
0 ignored issues
show
Documentation introduced by
$this->rules->getParsedRules() is of type array, but the function expects a object<Railt\Parser\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
74
        foreach ($this->rules->getDelegates() as $name => $delegate) {
75
            $parser->addDelegate($name, $delegate);
76
        }
77
78
        return $parser;
79
    }
80
}
81