LineMutation::originalLineNumber()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Static Analysis Results Baseliner (sarb).
5
 *
6
 * (c) Dave Liddament
7
 *
8
 * For the full copyright and licence information please view the LICENSE file distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser;
14
15
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\LineNumber;
16
17
final class LineMutation
18
{
19
    public static function originalLineNumber(LineNumber $lineNumber): self
20
    {
21
        return new self($lineNumber, null);
22
    }
23
24
    public static function newLineNumber(LineNumber $lineNumber): self
25
    {
26
        return new self(null, $lineNumber);
27
    }
28
29
    private function __construct(
30
        private ?LineNumber $originalLine,
31
        private ?LineNumber $newLine,
32
    ) {
33
    }
34
35
    public function getNewLine(): ?LineNumber
36
    {
37
        return $this->newLine;
38
    }
39
40
    public function getOriginalLine(): ?LineNumber
41
    {
42
        return $this->originalLine;
43
    }
44
45
    public function isAdded(): bool
46
    {
47
        return null !== $this->newLine;
48
    }
49
50
    /**
51
     * Returns true if other LineMutation is the same.
52
     */
53
    public function isEqual(?self $other): bool
54
    {
55
        if (null === $other) {
56
            return false;
57
        }
58
59
        if (!$this->isLineNumberEqual($this->newLine, $other->newLine)) {
60
            return false;
61
        }
62
63
        return $this->isLineNumberEqual($this->originalLine, $other->originalLine);
64
    }
65
66
    private function isLineNumberEqual(?LineNumber $a, ?LineNumber $b): bool
67
    {
68
        if (null === $a) {
69
            return null === $b;
70
        }
71
72
        if (null === $b) {
73
            return false;
74
        }
75
76
        return $a->getLineNumber() === $b->getLineNumber();
77
    }
78
}
79