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\internal; |
14
|
|
|
|
15
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\FileMutation; |
16
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\LineMutation; |
17
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\NewFileName; |
18
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\OriginalFileName; |
19
|
|
|
use Webmozart\Assert\Assert; |
20
|
|
|
|
21
|
|
|
class FileMutationBuilder |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var FileMutationsBuilder |
25
|
|
|
*/ |
26
|
|
|
private $fileMutationsBuilder; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var OriginalFileName|null |
30
|
|
|
*/ |
31
|
|
|
private $originalFileName; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var NewFileName|null |
35
|
|
|
*/ |
36
|
|
|
private $newFileName; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @psalm-var list<LineMutation> |
40
|
|
|
* |
41
|
|
|
* @var LineMutation[] |
42
|
|
|
*/ |
43
|
|
|
private $lineMutations; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* FileMutationBuilder constructor. |
47
|
|
|
*/ |
48
|
|
|
public function __construct(FileMutationsBuilder $fileMutationsBuilder) |
49
|
|
|
{ |
50
|
|
|
$this->fileMutationsBuilder = $fileMutationsBuilder; |
51
|
|
|
$this->lineMutations = []; |
52
|
|
|
$this->newFileName = null; |
53
|
|
|
$this->originalFileName = null; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setOriginalFileName(OriginalFileName $originalFileName): void |
57
|
|
|
{ |
58
|
|
|
Assert::null($this->originalFileName); |
59
|
|
|
$this->originalFileName = $originalFileName; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function setNewFileName(NewFileName $newFileName): void |
63
|
|
|
{ |
64
|
|
|
Assert::null($this->newFileName); |
65
|
|
|
$this->newFileName = $newFileName; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function addLineMutation(LineMutation $lineMutation): void |
69
|
|
|
{ |
70
|
|
|
$this->lineMutations[] = $lineMutation; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function build(): FileMutationsBuilder |
74
|
|
|
{ |
75
|
|
|
$fileMutation = new FileMutation( |
76
|
|
|
$this->originalFileName, |
77
|
|
|
$this->newFileName, |
78
|
|
|
$this->lineMutations); |
79
|
|
|
$this->fileMutationsBuilder->addFileMutation($fileMutation); |
80
|
|
|
|
81
|
|
|
return $this->fileMutationsBuilder; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function isAddedFile(): bool |
85
|
|
|
{ |
86
|
|
|
return (null === $this->originalFileName) && (null !== $this->newFileName); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|