Passed
Push — master ( c85748...2fd0ab )
by Petr
08:11
created

KeyValue::loadMultiple()   A

Complexity

Conditions 3
Paths 8

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 16
ccs 12
cts 12
cp 1
crap 3
rs 9.8666
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->setPathKey('key');
22 2
        $this->setContentKey('content');
23 2
        $this->setFormat(SinglePage::class);
24
    }
25
26 2
    public function loadMultiple(ARecord $record): array
27
    {
28 2
        $inPath = $this->getPathFromPk($record);
29 2
        $path = strval($record->offsetGet($inPath));
30 2
        $records = [];
31
        try {
32 2
            foreach ($this->getStorage()->lookup($path) as $contentKey) {
33 1
                $rec = clone $record;
34 1
                $rec->offsetSet($inPath, $path . $contentKey);
35 1
                $rec->load();
36 1
                $records[] = $rec;
37
            }
38 1
        } catch (StorageException $ex) {
39 1
            return [];
40
        }
41 1
        return $records;
42
    }
43
}
44