EntryAdapter::getClearRecord()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace kalanis\kw_pedigree\Storage\File;
4
5
6
use kalanis\kw_mapper\Search\Search;
7
use kalanis\kw_pedigree\PedigreeException;
8
use kalanis\kw_pedigree\Storage\AEntryAdapter;
9
use kalanis\kw_pedigree\Storage\APedigreeRecord;
10
11
12
/**
13
 * Class EntryAdapter
14
 * @package kalanis\kw_pedigree\Storage\File
15
 */
16
class EntryAdapter extends AEntryAdapter
17
{
18 1
    public function getChildren(): array
19
    {
20 1
        $search1 = new Search($this->getClearRecord());
21 1
        $search1->exact('motherId', strval($this->getLoadedRecord()->id));
22
23 1
        $search2 = new Search($this->getClearRecord());
24 1
        $search2->exact('fatherId', strval($this->getLoadedRecord()->id));
25
26
        // Files cannot use OR in their searches
27 1
        return $search1->getResults() + $search2->getResults();
28
    }
29
30 1
    public function setFatherId(?int $fatherId): ?bool
31
    {
32 1
        if ($this->getLoadedRecord()->fatherId != $fatherId) {
0 ignored issues
show
Bug Best Practice introduced by
The property fatherId does not exist on kalanis\kw_pedigree\Storage\APedigreeRecord. Since you implemented __get, consider adding a @property annotation.
Loading history...
33 1
            $this->getLoadedRecord()->fatherId = strval($fatherId);
0 ignored issues
show
Bug Best Practice introduced by
The property fatherId does not exist on kalanis\kw_pedigree\Storage\APedigreeRecord. Since you implemented __set, consider adding a @property annotation.
Loading history...
34 1
            return true;
35
        }
36 1
        return null;
37
    }
38
39 1
    public function getFatherId(): ?int
40
    {
41 1
        $data = $this->getLoadedRecord()->fatherId;
0 ignored issues
show
Bug Best Practice introduced by
The property fatherId does not exist on kalanis\kw_pedigree\Storage\APedigreeRecord. Since you implemented __get, consider adding a @property annotation.
Loading history...
42 1
        return !empty($data) ? intval($data) : null;
43
    }
44
45 1
    public function setMotherId(?int $motherId): ?bool
46
    {
47 1
        if ($this->getLoadedRecord()->motherId != $motherId) {
0 ignored issues
show
Bug Best Practice introduced by
The property motherId does not exist on kalanis\kw_pedigree\Storage\APedigreeRecord. Since you implemented __get, consider adding a @property annotation.
Loading history...
48 1
            $this->getLoadedRecord()->motherId = strval($motherId);
0 ignored issues
show
Bug Best Practice introduced by
The property motherId does not exist on kalanis\kw_pedigree\Storage\APedigreeRecord. Since you implemented __set, consider adding a @property annotation.
Loading history...
49 1
            return true;
50
        }
51 1
        return null;
52
    }
53
54 1
    public function getMotherId(): ?int
55
    {
56 1
        $data = $this->getLoadedRecord()->motherId;
0 ignored issues
show
Bug Best Practice introduced by
The property motherId does not exist on kalanis\kw_pedigree\Storage\APedigreeRecord. Since you implemented __get, consider adding a @property annotation.
Loading history...
57 1
        return !empty($data) ? intval($data) : null;
58
    }
59
60
    /**
61
     * @throws PedigreeException
62
     * @return PedigreeRecord
63
     */
64 9
    public function getLoadedRecord(): APedigreeRecord
65
    {
66 9
        return parent::getLoadedRecord();
67
    }
68
69
    /**
70
     * Unhook the original class, use only its definition and create new clear copy
71
     * @throws PedigreeException
72
     * @return APedigreeRecord
73
     */
74 1
    protected function getClearRecord(): APedigreeRecord
75
    {
76 1
        $record = get_class($this->getLoadedRecord());
77 1
        return new $record();
78
    }
79
}
80