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

CacheFactory::createSimpleCache()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 13
rs 10
ccs 0
cts 9
cp 0
crap 20
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