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\OriginalFileName; |
16
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils\StringUtils; |
17
|
|
|
|
18
|
|
|
final class FindOriginalFileNameState implements State |
19
|
|
|
{ |
20
|
|
|
private const RENAME_FROM = 'rename from '; |
21
|
|
|
private const ORIGINAL_FILE = '--- a/'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var FileMutationBuilder |
25
|
|
|
*/ |
26
|
|
|
private $fileMutationBuilder; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* FindOriginalFileNameState constructor. |
30
|
|
|
*/ |
31
|
|
|
public function __construct(FileMutationsBuilder $fileMutationsBuilder) |
32
|
|
|
{ |
33
|
|
|
$this->fileMutationBuilder = new FileMutationBuilder($fileMutationsBuilder); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function processLine(string $line): State |
37
|
|
|
{ |
38
|
|
|
if (LineTypeDetector::isFileAdded($line)) { |
39
|
|
|
return new FindNewFileNameState($this->fileMutationBuilder); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (StringUtils::startsWith(self::RENAME_FROM, $line)) { |
43
|
|
|
return $this->processAsRename($line); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (StringUtils::startsWith(self::ORIGINAL_FILE, $line)) { |
47
|
|
|
return $this->processAsChange($line); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function processAsRename(string $line): State |
54
|
|
|
{ |
55
|
|
|
$originalFileName = StringUtils::removeFromStart(self::RENAME_FROM, $line); |
56
|
|
|
$this->fileMutationBuilder->setOriginalFileName(new OriginalFileName($originalFileName)); |
57
|
|
|
|
58
|
|
|
return new FindRenameToState($this->fileMutationBuilder); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function processAsChange(string $line): State |
62
|
|
|
{ |
63
|
|
|
$originalFileName = StringUtils::removeFromStart(self::ORIGINAL_FILE, $line); |
64
|
|
|
$this->fileMutationBuilder->setOriginalFileName(new OriginalFileName($originalFileName)); |
65
|
|
|
|
66
|
|
|
return new FindNewFileNameState($this->fileMutationBuilder); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Signifies that the diff has finished. |
71
|
|
|
*/ |
72
|
|
|
public function finish(): void |
73
|
|
|
{ |
74
|
|
|
// Nothing to do. |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|