Code Duplication    Length = 29-31 lines in 2 locations

src/Plugin/Temporal.php 2 locations

@@ 26-54 (lines=29) @@
23
        $this->aggregator = new Aggregator($this);
24
    }
25
26
    public function getReference($entity, $id, $target, $date)
27
    {
28
        if (!$this->mapper->getSchema()->hasSpace('_temporal_reference_state')) {
29
            return;
30
        }
31
32
        $entity = $this->entityNameToId($entity);
33
        $target = $this->entityNameToId($target);
34
        $date = $this->getTimestamp($date);
35
36
        $rows = $this->mapper->getClient()->getSpace('_temporal_reference_state')
37
            ->select([$entity, $id, $target, $date], 0, 1, 0, 4) // [key, index, limit, offset, iterator = LE]
38
            ->getData();
39
40
        if (count($rows)) {
41
            $row = $rows[0];
42
            if ([$entity, $id, $target] == [$row[0], $row[1], $row[2]]) {
43
                $state = $this->mapper->findOne('_temporal_reference_state', [
44
                    'entity' => $entity,
45
                    'id' => $id,
46
                    'target' => $target,
47
                    'begin' => $row[3]
48
                ]);
49
                if (!$state->end || $state->end >= $date) {
50
                    return $state->targetId;
51
                }
52
            }
53
        }
54
    }
55
56
    public function getReferenceLog($entity, $id, $target)
57
    {
@@ 73-103 (lines=31) @@
70
        return $log;
71
    }
72
73
    public function getReferences($target, $targetId, $source, $date)
74
    {
75
        if (!$this->mapper->getSchema()->hasSpace('_temporal_reference_aggregate')) {
76
            return [];
77
        }
78
79
        $target = $this->entityNameToId($target);
80
        $source = $this->entityNameToId($source);
81
        $date = $this->getTimestamp($date);
82
83
        $rows = $this->mapper->getClient()->getSpace('_temporal_reference_aggregate')
84
            ->select([$target, $targetId, $source, $date], 0, 1, 0, 4) // [key, index, limit, offset, iterator = LE]
85
            ->getData();
86
87
        if (count($rows)) {
88
            $row = $rows[0];
89
            if ([$target, $targetId, $source] == [$row[0], $row[1], $row[2]]) {
90
                $state = $this->mapper->findOne('_temporal_reference_aggregate', [
91
                    'entity' => $target,
92
                    'id'     => $targetId,
93
                    'source' => $source,
94
                    'begin'  => $row[3]
95
                ]);
96
97
                if (!$state->end || $state->end > $date) {
98
                    return $state->data;
99
                }
100
            }
101
        }
102
        return [];
103
    }
104
105
    public function reference(array $reference)
106
    {