Completed
Push — master ( 65570c...bf6ec7 )
by Arne
03:29 queued 12s
created

IndexObjectDifference   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
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 5
A getRelativePath() 0 4 1
A getIndexObjectA() 0 4 1
A getIndexObjectB() 0 4 1
1
<?php
2
3
namespace Storeman\Index\Diff;
4
5
use Storeman\Index\IndexObject;
6
7
/**
8
 * Represents the difference between two index objects.
9
 */
10
class IndexObjectDifference
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $relativePath;
16
17
    /**
18
     * @var IndexObject
19
     */
20
    protected $indexObjectA;
21
22
    /**
23
     * @var IndexObject
24
     */
25
    protected $indexObjectB;
26
27
    public function __construct(?IndexObject $indexObjectA, ?IndexObject $indexObjectB)
28
    {
29
        assert(($indexObjectA === null) xor ($indexObjectB === null));
30
        assert(
31
            ($indexObjectA === null || $indexObjectB === null) ||
32
            ($indexObjectA->getRelativePath() === $indexObjectB->getRelativePath())
33
        );
34
35
        if ($indexObjectA instanceof IndexObject)
36
        {
37
            $this->relativePath = $indexObjectA->getRelativePath();
38
        }
39
        elseif ($indexObjectB instanceof IndexObject)
40
        {
41
            $this->relativePath = $indexObjectB->getRelativePath();
42
        }
43
        else
44
        {
45
            throw new \LogicException();
46
        }
47
48
        $this->indexObjectA = $indexObjectA;
49
        $this->indexObjectB = $indexObjectB;
50
    }
51
52
    public function getRelativePath(): string
53
    {
54
        return $this->relativePath;
55
    }
56
57
    public function getIndexObjectA(): ?IndexObject
58
    {
59
        return $this->indexObjectA;
60
    }
61
62
    public function getIndexObjectB(): ?IndexObject
63
    {
64
        return $this->indexObjectB;
65
    }
66
}
67