CacheFactory::createSimpleCache()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 14
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 14
rs 10
ccs 0
cts 9
cp 0
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\Cache;
13
14
use ForecastAutomation\Kernel\AbstractFactory;
15
use Shieldon\SimpleCache\Cache;
16
17
class CacheFactory extends AbstractFactory
18
{
19
    public function createSimpleCache(): Cache
20
    {
21
        if (! file_exists('/tmp/simple-cache')
22
            && ! mkdir('/tmp/simple-cache', 0777, true)
23
            && ! is_dir(
24
                '/tmp/simple-cache'
25
            )) {
26
            throw new \RuntimeException(sprintf('Directory "%s" was not created', '/tmp/simple-cache'));
27
        }
28
29
        return new Cache(
30
            $this->getCacheType(),
31
            [
32
                'storage' => '/tmp/simple-cache',
33
            ]
34
        );
35
    }
36
37
    public function getCacheType(): string
38
    {
39
        return 'file';
40
    }
41
}
42