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

BaseTokens::setGroup()   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 $skipped = [];
26
27
    /**
28
     * @param string $token
29
     * @param string $pcre
30
     */
31
    protected function setToken(string $token, string $pcre): void
32
    {
33
        $this->tokens[$token] = $pcre;
34
    }
35
36
    /**
37
     * @param string $token
38
     */
39
    protected function makeSkipped(string $token): void
40
    {
41
        $this->skipped[] = $token;
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function all(): array
48
    {
49
        return $this->tokens;
50
    }
51
52
    /**
53
     * @param string $token
54
     * @return bool
55
     */
56
    public function isKeep(string $token): bool
57
    {
58
        return ! \in_array($token, $this->skipped, true);
59
    }
60
61
    /**
62
     * @param string $token
63
     * @return bool
64
     */
65
    public function has(string $token): bool
66
    {
67
        return \array_key_exists($token, $this->tokens);
68
    }
69
}
70