Passed
Pull Request — master (#43)
by Buster
09:23
created

Psr6CacheFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\MoTranslator\Cache;
6
7
use PhpMyAdmin\MoTranslator\MoParser;
8
use Psr\Cache\CacheItemPoolInterface;
9
10
final class Psr6CacheFactory implements CacheFactoryInterface
11
{
12
    /** @var CacheItemPoolInterface */
13
    private $psr6Cache;
14
15
    /** @var int */
16
    private $ttl;
17
18
    /** @var bool */
19
    private $reloadOnMiss;
20
21
    /** @var string */
22
    private $prefix;
23
24
    /** @var string */
25
    private $separator;
26
27
    public function __construct(
28
        CacheItemPoolInterface $psr6Cache,
29
        int $ttl = 0,
30
        bool $reloadOnMiss = true,
31
        string $prefix = 'mo_',
32
        string $separator = '.'
33
    ) {
34
        $this->psr6Cache = $psr6Cache;
35
        $this->ttl = $ttl;
36
        $this->reloadOnMiss = $reloadOnMiss;
37
        $this->prefix = $prefix;
38
        $this->separator = $separator;
39
    }
40
41
    public function getInstance(MoParser $parser, string $locale, string $domain): CacheInterface
42
    {
43
        return new Psr6Cache(
44
            $this->psr6Cache,
45
            $parser,
46
            $locale,
47
            $domain,
48
            $this->ttl,
49
            $this->reloadOnMiss,
50
            $this->prefix,
51
            $this->separator
52
        );
53
    }
54
}
55