Passed
Push — master ( ae1a26...486cfe )
by Petr
03:11
created

APreset::loadRecord()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.9666
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace kalanis\kw_mapper\Mappers;
4
5
6
use kalanis\kw_mapper\MapperException;
7
use kalanis\kw_mapper\Records;
8
9
10
/**
11
 * Class APreset
12
 * @package kalanis\kw_mapper\Mappers
13
 * Abstract for manipulation with constant content as table
14
 *
15
 * You just need to extend this class and set datasource array and correct map.
16
 */
17
abstract class APreset extends AMapper
18
{
19
    use TFinder;
20
    use TStore;
21
22 2
    public function getAlias(): string
23
    {
24 2
        return $this->getSource();
25
    }
26
27 1
    protected function insertRecord(Records\ARecord $record): bool
28
    {
29 1
        throw new MapperException('Cannot insert record into predefined array');
30
    }
31
32 1
    protected function updateRecord(Records\ARecord $record): bool
33
    {
34 1
        throw new MapperException('Cannot update record in predefined array');
35
    }
36
37
    /**
38
     * @param Records\ARecord|Records\PageRecord $record
39
     * @throws MapperException
40
     * @return int
41
     */
42 1
    public function countRecord(Records\ARecord $record): int
43
    {
44 1
        return count($this->findMatched($record));
45
    }
46
47
    /**
48
     * @param Records\ARecord|Records\PageRecord $record
49
     * @throws MapperException
50
     * @return bool
51
     */
52 2
    protected function loadRecord(Records\ARecord $record): bool
53
    {
54 2
        $matches = $this->findMatched($record);
55 2
        if (empty($matches)) { // nothing found
56 1
            return false;
57
        }
58
59 1
        reset($matches);
60 1
        $dataLine = & $this->records[key($matches)];
61 1
        foreach ($this->getRelations() as $objectKey => $recordKey) {
62 1
            $entry = $record->getEntry($objectKey);
63 1
            $entry->setData($dataLine->offsetGet($objectKey), true);
64
        }
65 1
        return true;
66
    }
67
68 1
    protected function deleteRecord(Records\ARecord $record): bool
69
    {
70 1
        throw new MapperException('Cannot delete record in predefined array');
71
    }
72
73
    /**
74
     * @param Records\ARecord $record
75
     * @throws MapperException
76
     * @return Records\ARecord[]
77
     */
78 1
    public function loadMultiple(Records\ARecord $record): array
79
    {
80 1
        return $this->findMatched($record);
81
    }
82
83
    /**
84
     * @param array<string|int, string|int|float|array<string|int, string|int|array<string|int, string|int>>> $content
85
     * @throws MapperException
86
     * @return bool
87
     * @codeCoverageIgnore should not be accessible
88
     */
89
    protected function saveToStorage(array $content): bool
0 ignored issues
show
Unused Code introduced by
The parameter $content is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
    protected function saveToStorage(/** @scrutinizer ignore-unused */ array $content): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
    {
91
        throw new MapperException('Cannot save records in predefined array');
92
    }
93
}
94