GacelaFileCache::resetCache()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver\Cache;
6
7
use Gacela\Framework\Config\ConfigInterface;
8
9
final class GacelaFileCache
10
{
11
    public const KEY_ENABLED = 'gacela-cache-enabled';
12
13
    public const DEFAULT_ENABLED_VALUE = false;
14
15
    public const DEFAULT_DIRECTORY_VALUE = null;
16
17
    private static ?bool $isEnabled = null;
18
19
    public function __construct(
20
        private readonly ConfigInterface $config,
21
    ) {
22
    }
23
24
    /**
25
     * @internal
26
     */
27
    public static function resetCache(): void
28
    {
29
        self::$isEnabled = null;
30
    }
31
32
    public function isEnabled(): bool
33
    {
34
        if (self::$isEnabled === null) {
35
            self::$isEnabled = $this->config->hasKey(self::KEY_ENABLED)
36
                ? (bool)$this->config->get(self::KEY_ENABLED)
37
                : $this->config->getSetupGacela()->isFileCacheEnabled();
38
        }
39
40
        return self::$isEnabled;
41
    }
42
}
43