Completed
Push — master ( 69b695...671bd7 )
by Kirill
06:49
created

BaseTokens::setToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 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
12
/**
13
 * Class BaseTokens
14
 */
15
abstract class BaseTokens implements ProvideTokens
16
{
17
    /**
18
     * @var array
19
     */
20
    private $tokens = [];
21
22
    /**
23
     * @var array
24
     */
25
    private $groups = [];
26
27
    /**
28
     * @var array
29
     */
30
    private $skipped = [];
31
32
    /**
33
     * @param string $token
34
     * @param string $pcre
35
     */
36
    protected function setToken(string $token, string $pcre): void
37
    {
38
        $this->tokens[$token] = $pcre;
39
    }
40
41
    /**
42
     * @param string $token
43
     */
44
    protected function makeSkipped(string $token): void
45
    {
46
        $this->skipped[] = $token;
47
    }
48
49
    /**
50
     * @param string $token
51
     * @param int $group
52
     */
53
    protected function setGroup(string $token, int $group): void
54
    {
55
        $this->groups[$token] = $group;
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function all(): array
62
    {
63
        return $this->tokens;
64
    }
65
66
    /**
67
     * @param string $token
68
     * @return bool
69
     */
70
    public function isKeep(string $token): bool
71
    {
72
        return ! \in_array($token, $this->skipped, true);
73
    }
74
75
    /**
76
     * @param string $token
77
     * @return int
78
     */
79
    public function getGroup(string $token): int
80
    {
81
        return $this->groups[$token] ?? 0;
82
    }
83
}
84