Passed
Push — feature/gacela-file-cache ( a1109a...a7fc9c )
by Jesús
03:57
created

GacelaProfiler::resetCache()   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
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver\Profiler;
6
7
use Gacela\Framework\Config\ConfigInterface;
8
9
final class GacelaProfiler
10
{
11
    public const KEY_ENABLED = 'gacela-profiler-enabled';
12
    public const DEFAULT_ENABLED_VALUE = false;
13
    public const DEFAULT_DIRECTORY_VALUE = '/.gacela/profiler';
14
15
    private static ?bool $isEnabled = null;
16
17
    private ConfigInterface $config;
18
19 51
    public function __construct(ConfigInterface $config)
20
    {
21 51
        $this->config = $config;
22
    }
23
24
    /**
25
     * @internal
26
     */
27 14
    public static function resetCache(): void
28
    {
29 14
        self::$isEnabled = null;
30
    }
31
32 51
    public function isEnabled(): bool
33
    {
34 51
        if (self::$isEnabled === null) {
35 14
            self::$isEnabled = $this->config->hasKey(self::KEY_ENABLED)
36 2
                ? (bool)$this->config->get(self::KEY_ENABLED)
37 12
                : $this->config->getSetupGacela()->isProfilerEnabled();
38
        }
39
40 51
        return self::$isEnabled;
1 ignored issue
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...
41
    }
42
}
43