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

IndexObjectComparison   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 6
A getRelativePath() 0 4 1
A getIndexObjectA() 0 4 1
A getIndexObjectB() 0 4 1
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