Completed
Push — master ( c79300...9eb332 )
by Arne
02:48
created

IndexObjectComparison::__construct()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9137
c 0
b 0
f 0
cc 6
nc 3
nop 2
1
<?php
2
3
namespace Storeman\Index\Comparison;
4
5
use Storeman\Index\IndexObject;
6
7
class IndexObjectComparison
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $relativePath;
13
14
    /**
15
     * @var IndexObject
16
     */
17
    protected $indexObjectA;
18
19
    /**
20
     * @var IndexObject
21
     */
22
    protected $indexObjectB;
23
24
    public function __construct(?IndexObject $indexObjectA, ?IndexObject $indexObjectB)
25
    {
26
        assert(!(($indexObjectA === null) && ($indexObjectB === null)));
27
        assert(
28
            ($indexObjectA === null || $indexObjectB === null) ||
29
            ($indexObjectA->getRelativePath() === $indexObjectB->getRelativePath())
30
        );
31
32
        if ($indexObjectA instanceof IndexObject)
33
        {
34
            $this->relativePath = $indexObjectA->getRelativePath();
35
        }
36
        elseif ($indexObjectB instanceof IndexObject)
37
        {
38
            $this->relativePath = $indexObjectB->getRelativePath();
39
        }
40
        else
41
        {
42
            throw new \LogicException();
43
        }
44
45
        $this->indexObjectA = $indexObjectA;
46
        $this->indexObjectB = $indexObjectB;
47
    }
48
49
    public function getRelativePath(): string
50
    {
51
        return $this->relativePath;
52
    }
53
54
    public function getIndexObjectA(): ?IndexObject
55
    {
56
        return $this->indexObjectA;
57
    }
58
59
    public function getIndexObjectB(): ?IndexObject
60
    {
61
        return $this->indexObjectB;
62
    }
63
}
64