Passed
Pull Request — master (#947)
by
unknown
20:18
created

TokenizerConfig::isLoadInterfacesEnabled()   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
     *     debug: bool,
27
     *     directories: TDirectories,
28
     *     exclude: TDirectories,
29
     *     scopes: array<non-empty-string, TScope>
30
     * }
31
     */
32
    protected array $config = [
33
        'cache' => [
34
            'directory' => null,
35
            'enabled' => false,
36
        ],
37
        'load' => [
38
            'classes' => true,
39
            'enums' => true,
40
            'interfaces' => false,
41
        ],
42
        'debug' => false,
43
        'directories' => [],
44
        'exclude' => [],
45
        'scopes' => [],
46
    ];
47
48 384
    public function isDebug(): bool
49
    {
50 384
        return (bool)($this->config['debug'] ?? false);
51
    }
52
53
    /**
54
     * @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...
55
     */
56 381
    public function getDirectories(): array
57
    {
58 381
        return $this->config['directories'] ?? [(string)\getcwd()];
59
    }
60
61
    /**
62
     * @return TDirectories
63
     */
64 385
    public function getExcludes(): array
65
    {
66 385
        return $this->config['exclude'] ?? ['vendor', 'tests'];
67
    }
68
69
    /**
70
     * @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...
71
     */
72 27
    public function getScope(string $scope): array
73
    {
74 27
        $directories = $this->config['scopes'][$scope]['directories'] ?? $this->getDirectories();
75 27
        $excludes = $this->config['scopes'][$scope]['exclude'] ?? $this->getExcludes();
76
77 27
        return [
78 27
            'directories' => $directories,
79 27
            'exclude' => $excludes,
80 27
        ];
81
    }
82
83
    /**
84
     * Check if tokenizer listeners cache is enabled.
85
     */
86 368
    public function isCacheEnabled(): bool
87
    {
88 368
        return (bool)($this->config['cache']['enabled'] ?? false);
89
    }
90
91
    /**
92
     * Get tokenizer listeners cache directory.
93
     */
94 368
    public function getCacheDirectory(): ?string
95
    {
96 368
        $dir = $this->config['cache']['directory'] ?? null;
97 368
        \assert(\is_string($dir) || $dir === null, 'Invalid cache directory.');
98
99 368
        return $dir;
100
    }
101
102 355
    public function isLoadClassesEnabled(): bool
103
    {
104 355
        return (bool) ($this->config['load']['classes'] ?? true);
105
    }
106
107 355
    public function isLoadEnumsEnabled(): bool
108
    {
109 355
        return (bool) ($this->config['load']['enums'] ?? false);
110
    }
111
112 355
    public function isLoadInterfacesEnabled(): bool
113
    {
114 355
        return (bool) ($this->config['load']['interfaces'] ?? false);
115
    }
116
}
117