Completed
Push — master ( db8578...85f9c3 )
by Kirill
10:30
created

BasePragmas::verifyPragmaName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
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;
11
12
use Railt\Parser\Configuration;
13
14
/**
15
 * Class BasePragmas
16
 */
17
abstract class BasePragmas implements ProvidePragmas
18
{
19
    /**
20
     * @var string
21
     */
22
    public const GROUP_PARSER = 'parser';
23
24
    /**
25
     * @var string
26
     */
27
    public const GROUP_LEXER = 'lexer';
28
29
    /**
30
     * @var string
31
     */
32
    public const GROUP_GRAMMAR = 'grammar';
33
34
    /**
35
     * @var array|Config[]
36
     */
37
    private $resolvers;
38
39
    /**
40
     * @var array
41
     */
42
    private $configs = [];
43
44
    /**
45
     * PragmaResolver constructor.
46
     */
47
    public function __construct()
48
    {
49
        $this->bootResolvers();
50
    }
51
52
    /**
53
     * @return void
54
     */
55
    private function bootResolvers(): void
56
    {
57
        $this->resolvers[self::GROUP_PARSER]  = $this->getParserResolver();
58
        $this->resolvers[self::GROUP_LEXER]   = $this->getLexerResolver();
59
        $this->resolvers[self::GROUP_GRAMMAR] = $this->getGrammarResolver();
60
    }
61
62
    /**
63
     * @return Config
64
     */
65
    private function getParserResolver(): Config
66
    {
67
        return new Config(self::GROUP_PARSER, [
68
            Configuration::PRAGMA_ROOT,
69
            Configuration::PRAGMA_LOOKAHEAD,
70
            Configuration::PRAGMA_RUNTIME,
71
        ]);
72
    }
73
74
    /**
75
     * @return Config
76
     */
77
    private function getLexerResolver(): Config
78
    {
79
        return new Config(self::GROUP_LEXER, [
80
            // TODO
81
        ]);
82
    }
83
84
    /**
85
     * @return Config
86
     */
87
    private function getGrammarResolver(): Config
88
    {
89
        return new Config(self::GROUP_GRAMMAR, [
90
            // TODO
91
        ]);
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function parser(): array
98
    {
99
        return $this->configs[self::GROUP_GRAMMAR] ?? [];
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function lexer(): array
106
    {
107
        return $this->configs[self::GROUP_LEXER] ?? [];
108
    }
109
110
    /**
111
     * @return array
112
     */
113
    public function grammar(): array
114
    {
115
        return $this->configs[self::GROUP_GRAMMAR] ?? [];
116
    }
117
118
    /**
119
     * @return iterable|Config[]
120
     */
121
    protected function getResolvers(): iterable
122
    {
123
        return $this->resolvers;
124
    }
125
126
    /**
127
     * @param string $group
128
     * @param string $name
129
     * @param string $value
130
     */
131
    protected function set(string $group, string $name, string $value): void
132
    {
133
        if (! \array_key_exists($group, $this->configs)) {
134
            $this->configs[$group] = [];
135
        }
136
137
        $this->configs[$group][$name] = $value;
138
    }
139
140
    /**
141
     * @return array
142
     */
143
    public function __debugInfo(): array
144
    {
145
        return $this->configs;
146
    }
147
}
148