Passed
Branch main (d16050)
by Chema
19:21 queued 15:06
created

GacelaFileCache::isEnabledFromCacheConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver\Cache;
6
7
use Gacela\Framework\Bootstrap\CacheConfigurationInterface;
8
use Gacela\Framework\Config\ConfigInterface;
9
10
final class GacelaFileCache
11
{
12
    public const KEY_ENABLED = 'gacela-cache-enabled';
13
14
    public const DEFAULT_ENABLED_VALUE = false;
15
16
    public const DEFAULT_DIRECTORY_VALUE = null;
17 57
18
    private static ?bool $isEnabled = null;
19
20 57
    public function __construct(
21
        private readonly ConfigInterface $config,
22
    ) {
23
    }
24
25 58
    /**
26
     * @internal
27 58
     */
28
    public static function resetCache(): void
29
    {
30 57
        self::$isEnabled = null;
31
    }
32 57
33 53
    public function isEnabled(): bool
34 6
    {
35 47
        if (self::$isEnabled === null) {
36
            self::$isEnabled = $this->config->hasKey(self::KEY_ENABLED)
37
                ? (bool)$this->config->get(self::KEY_ENABLED)
38 57
                : $this->config->getSetupGacela()->isFileCacheEnabled();
39
        }
40
41
        return self::$isEnabled;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::isEnabled could return the type null which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
42
    }
43
44
    public static function isEnabledFromCacheConfig(CacheConfigurationInterface $cacheConfig): bool
45
    {
46
        if (self::$isEnabled === null) {
47
            self::$isEnabled = $cacheConfig->isFileCacheEnabled();
48
        }
49
50
        return self::$isEnabled;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::isEnabled could return the type null which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
51
    }
52
}
53