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

BaseTokens   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 3
cbo 0
dl 0
loc 69
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setToken() 0 4 1
A makeSkipped() 0 4 1
A setGroup() 0 4 1
A all() 0 4 1
A isKeep() 0 4 1
A getGroup() 0 4 1
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