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

BaseTokens   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 0
dl 0
loc 55
c 0
b 0
f 0
ccs 0
cts 20
cp 0
rs 10

5 Methods

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