IndexComparison::getObjectComparison()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Storeman\Index\Comparison;
4
5
class IndexComparison implements \Countable, \IteratorAggregate
6
{
7
    /**
8
     * @var IndexObjectComparison[]
9
     */
10
    protected $objectComparisons = [];
11
12
    public function addObjectComparison(IndexObjectComparison $objectComparison): IndexComparison
13
    {
14
        $this->objectComparisons[$objectComparison->getRelativePath()] = $objectComparison;
15
16
        return $this;
17
    }
18
19
    public function getObjectComparison(string $path): ?IndexObjectComparison
20
    {
21
        return array_key_exists($path, $this->objectComparisons) ? $this->objectComparisons[$path] : null;
22
    }
23
24
    public function hasObjectComparison(string $path): bool
25
    {
26
        return array_key_exists($path, $this->objectComparisons);
27
    }
28
29
    /**
30
     * Merges the given comparison set into this set.
31
     * There must be an empty intersection between the path sets of both comparisons.
32
     *
33
     * @param IndexComparison $other
34
     * @return IndexComparison
35
     */
36
    public function merge(IndexComparison $other): IndexComparison
37
    {
38
        assert(empty(array_intersect(array_keys($this->objectComparisons), array_keys($other->objectComparisons))));
39
40
        $this->objectComparisons = array_merge($this->objectComparisons, $other->objectComparisons);
41
42
        return $this;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function count()
49
    {
50
        return count($this->objectComparisons);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getIterator()
57
    {
58
        return new \ArrayIterator($this->objectComparisons);
59
    }
60
}
61