InMemoryCache::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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 array $cache = [];
15
16 896
    public function __construct(MoParser $parser)
17
    {
18 896
        $parser->parseIntoCache($this);
19 896
    }
20 128
21
    public function get(string $msgid): string
22 728
    {
23
        return array_key_exists($msgid, $this->cache) ? $this->cache[$msgid] : $msgid;
24 728
    }
25
26
    public function set(string $msgid, string $msgstr): void
27 658
    {
28
        $this->cache[$msgid] = $msgstr;
29 658
    }
30 94
31
    public function has(string $msgid): bool
32 490
    {
33
        return array_key_exists($msgid, $this->cache);
34 490
    }
35
36
    /** @inheritDoc */
37 42
    public function setAll(array $translations): void
38
    {
39 42
        $this->cache = $translations;
40 6
    }
41
42
    /** @inheritDoc */
43
    public function getAll(): array
44
    {
45 28
        return $this->cache;
46
    }
47
}
48