Passed
Push — master ( 02118d...11fb63 )
by Petr
03:00
created

TReadFileTable::countRecord()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace kalanis\kw_mapper\Mappers\Shared;
4
5
6
use kalanis\kw_mapper\MapperException;
7
use kalanis\kw_mapper\Records;
8
9
10
/**
11
 * Trait TReadFileTable
12
 * @package kalanis\kw_mapper\Mappers\Shared
13
 * Abstract for manipulation with file content as table - read content
14
 */
15
trait TReadFileTable
16
{
17
    use TFinder;
18
    use TStore;
19
20
    /**
21
     * @param Records\ARecord|Records\PageRecord $record
22
     * @throws MapperException
23
     * @return int
24
     */
25 1
    public function countRecord(Records\ARecord $record): int
26
    {
27 1
        return count($this->findMatched($record));
28
    }
29
30
    /**
31
     * @param Records\ARecord|Records\PageRecord $record
32
     * @throws MapperException
33
     * @return bool
34
     */
35 6
    protected function loadRecord(Records\ARecord $record): bool
36
    {
37 6
        $this->clearSource();
38 6
        $matches = $this->findMatched($record);
39 6
        if (empty($matches)) { // nothing found
40 2
            return false;
41
        }
42
43 5
        reset($matches);
44 5
        $dataLine = & $this->records[key($matches)];
45 5
        foreach ($this->getRelations() as $objectKey => $recordKey) {
46 5
            $entry = $record->getEntry($objectKey);
47 5
            $entry->setData($dataLine->offsetGet($objectKey), true);
48
        }
49 5
        return true;
50
    }
51
52
    /**
53
     * @param Records\ARecord $record
54
     * @throws MapperException
55
     * @return Records\ARecord[]
56
     */
57 15
    public function loadMultiple(Records\ARecord $record): array
58
    {
59 15
        return array_values($this->findMatched($record));
60
    }
61
}
62