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

GacelaCache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 30
rs 10
ccs 10
cts 10
cp 1
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isProjectCacheEnabled() 0 7 2
A isCacheFromSetupGacelaDisabled() 0 3 1
A isCacheFromApplicationConfigEnabled() 0 3 1
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