Passed
Pull Request — master (#186)
by Jesús
06:27 queued 03:12
created

GacelaCache::__construct()   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
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\Config\ConfigInterface;
8
9
final class GacelaCache
10
{
11
    public const KEY_ENABLED = 'gacela-cache-enabled';
12
    public const DEFAULT_ENABLED_VALUE = true;
13
    public const DEFAULT_DIRECTORY_VALUE = '.gacela/cache';
14
15
    private ConfigInterface $config;
16
17 35
    public function __construct(ConfigInterface $config)
18
    {
19 35
        $this->config = $config;
20
    }
21
22 35
    public function isProjectCacheEnabled(): bool
23
    {
24 35
        if ($this->isCacheFromSetupGacelaDisabled()) {
25 2
            return false;
26
        }
27
28 33
        return $this->isCacheFromApplicationConfigEnabled();
29
    }
30
31 35
    private function isCacheFromSetupGacelaDisabled(): bool
32
    {
33 35
        return !$this->config->getSetupGacela()->isCacheEnabled();
34
    }
35
36 33
    private function isCacheFromApplicationConfigEnabled(): bool
37
    {
38 33
        return (bool) $this->config->get(self::KEY_ENABLED, self::DEFAULT_ENABLED_VALUE);
39
    }
40
}
41