Passed
Push — master ( 122983...91227d )
by William
02:34 queued 26s
created

InMemoryCache   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 37
ccs 16
cts 16
cp 1
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 3 1
A __construct() 0 4 1
A setAll() 0 3 1
A has() 0 3 1
A getAll() 0 3 1
A get() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\MoTranslator\Cache;
6
7
use PhpMyAdmin\MoTranslator\MoParser;
8
9
use function array_key_exists;
10
11
final class InMemoryCache implements CacheInterface, GetAllInterface
12
{
13
    /** @var array<string, string> */
14
    private $cache;
15
16 256
    public function __construct(MoParser $parser)
17
    {
18 256
        $this->cache = [];
19 256
        $parser->parseIntoCache($this);
20 64
    }
21
22 208
    public function get(string $msgid): string
23
    {
24 208
        return array_key_exists($msgid, $this->cache) ? $this->cache[$msgid] : $msgid;
25
    }
26
27 188
    public function set(string $msgid, string $msgstr): void
28
    {
29 188
        $this->cache[$msgid] = $msgstr;
30 47
    }
31
32 140
    public function has(string $msgid): bool
33
    {
34 140
        return array_key_exists($msgid, $this->cache);
35
    }
36
37 12
    public function setAll(array $translations): void
38
    {
39 12
        $this->cache = $translations;
40 3
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 8
    public function getAll(): array
46
    {
47 8
        return $this->cache;
48
    }
49
}
50