Passed
Push — master ( 813f0f...a309d2 )
by butschster
09:30 queued 12s
created

TokenizerConfig::isLoadEnumsEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Tokenizer\Config;
6
7
use Spiral\Core\InjectableConfig;
8
9
/**
10
 * Tokenizer component configuration.
11
 *
12
 * @psalm-type TDirectories = array<array-key, string>
13
 *
14
 * @psalm-type TScope = array{
15
 *     "directories": TDirectories,
16
 *     "exclude": TDirectories
17
 * }
18
 */
19
final class TokenizerConfig extends InjectableConfig
20
{
21
    public const CONFIG = 'tokenizer';
22
23
    /**
24
     * @var array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
25
     *     cache: array{directory: null, enabled: bool},
26
     *     load: array{classes:bool, enums: bool, interfaces: bool},
27
     *     debug: bool,
28
     *     directories: TDirectories,
29
     *     exclude: TDirectories,
30
     *     scopes: array<non-empty-string, TScope>
31
     * }
32
     */
33
    protected array $config = [
34
        'cache' => [
35
            'directory' => null,
36
            'enabled' => false,
37
        ],
38
        'load' => [
39
            'classes' => true,
40
            'enums' => false,
41
            'interfaces' => false,
42
        ],
43
        'debug' => false,
44
        'directories' => [],
45
        'exclude' => [],
46
        'scopes' => [],
47
    ];
48
49 398
    public function isDebug(): bool
50
    {
51 398
        return (bool)($this->config['debug'] ?? false);
52
    }
53
54
    /**
55
     * @return TDirectories
0 ignored issues
show
Bug introduced by
The type Spiral\Tokenizer\Config\TDirectories was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
     */
57 393
    public function getDirectories(): array
58
    {
59 393
        return $this->config['directories'] ?? [(string)\getcwd()];
60
    }
61
62
    /**
63
     * @return TDirectories
64
     */
65 399
    public function getExcludes(): array
66
    {
67 399
        return $this->config['exclude'] ?? ['vendor', 'tests'];
68
    }
69
70
    /**
71
     * @return TScope
0 ignored issues
show
Bug introduced by
The type Spiral\Tokenizer\Config\TScope was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
     */
73 31
    public function getScope(string $scope): array
74
    {
75 31
        $directories = $this->config['scopes'][$scope]['directories'] ?? $this->getDirectories();
76 31
        $excludes = $this->config['scopes'][$scope]['exclude'] ?? $this->getExcludes();
77
78 31
        return [
79 31
            'directories' => $directories,
80 31
            'exclude' => $excludes,
81 31
        ];
82
    }
83
84
    /**
85
     * Check if tokenizer listeners cache is enabled.
86
     */
87 368
    public function isCacheEnabled(): bool
88
    {
89 368
        return (bool)($this->config['cache']['enabled'] ?? false);
90
    }
91
92
    /**
93
     * Get tokenizer listeners cache directory.
94
     */
95 368
    public function getCacheDirectory(): ?string
96
    {
97 368
        $dir = $this->config['cache']['directory'] ?? null;
98 368
        \assert(\is_string($dir) || $dir === null, 'Invalid cache directory.');
99
100 368
        return $dir;
101
    }
102
103 357
    public function isLoadClassesEnabled(): bool
104
    {
105 357
        return (bool) ($this->config['load']['classes'] ?? true);
106
    }
107
108 357
    public function isLoadEnumsEnabled(): bool
109
    {
110 357
        return (bool) ($this->config['load']['enums'] ?? false);
111
    }
112
113 357
    public function isLoadInterfacesEnabled(): bool
114
    {
115 357
        return (bool) ($this->config['load']['interfaces'] ?? false);
116
    }
117
}
118