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

Psr6CacheFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getInstance() 0 11 1
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