KeyValue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 26
ccs 17
cts 17
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadMultiple() 0 16 3
A setMap() 0 6 1
1
<?php
2
3
namespace kalanis\kw_mapper\Mappers\Storage;
4
5
6
use kalanis\kw_mapper\Records\ARecord;
7
use kalanis\kw_mapper\Storage\Shared\FormatFiles\SinglePage;
8
use kalanis\kw_storage\StorageException;
9
10
11
/**
12
 * Class KeyValue
13
 * @package kalanis\kw_mapper\Mappers\Storage
14
 * Key-value pairs somewhere in storage mapped for extra usage
15
 * It can be a file, it can be an entry in Redis, Memcache or other sources
16
 */
17
class KeyValue extends AFile
18
{
19 2
    protected function setMap(): void
20
    {
21 2
        $this->setStorage();
22 2
        $this->setPathKey('key');
23 2
        $this->setContentKey('content');
24 2
        $this->setFormat(SinglePage::class);
25
    }
26
27 2
    public function loadMultiple(ARecord $record): array
28
    {
29 2
        $inPath = $this->getPathFromPk($record);
30 2
        $path = strval($record->offsetGet($inPath));
31 2
        $records = [];
32
        try {
33 2
            foreach ($this->getStorage()->lookup($path) as $contentKey) {
34 1
                $rec = clone $record;
35 1
                $rec->offsetSet($inPath, $path . $contentKey);
36 1
                $rec->load();
37 1
                $records[] = $rec;
38
            }
39 1
        } catch (StorageException $ex) {
40 1
            return [];
41
        }
42 1
        return $records;
43
    }
44
}
45