Passed
Push — master ( f6e659...bb9ac5 )
by Patrick
04:00
created

CacheFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createSimpleCache() 0 13 4
A getCacheType() 0 3 1
1
<?php
2
3
namespace ForecastAutomation\Cache;
4
5
use ForecastAutomation\Kernel\AbstractFactory;
6
use Shieldon\SimpleCache\Cache;
7
8
class CacheFactory extends AbstractFactory
9
{
10
    public function createSimpleCache(): Cache
11
    {
12
        if (!file_exists('/tmp/simple-cache')
13
            && !mkdir('/tmp/simple-cache', 0777, true)
14
            && !is_dir(
15
                '/tmp/simple-cache'
16
            )) {
17
            throw new \RuntimeException(sprintf('Directory "%s" was not created', '/tmp/simple-cache'));
18
        }
19
20
        return new Cache(
21
            $this->getCacheType(), [
22
                'storage' => '/tmp/simple-cache',
23
            ]
24
        );
25
    }
26
27
    public function getCacheType(): string
28
    {
29
        return 'file';
30
    }
31
}
32