|
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\Plugins\GitDiffHistoryAnalyser; |
|
14
|
|
|
|
|
15
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\ProjectRoot; |
|
16
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryAnalyser; |
|
17
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryAnalyserException; |
|
18
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryFactory; |
|
19
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryMarker; |
|
20
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryMarkerFactory; |
|
21
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\Parser; |
|
22
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\GitDiffHistoryAnalyser\internal\GitWrapper; |
|
23
|
|
|
use Webmozart\Assert\Assert; |
|
24
|
|
|
|
|
25
|
|
|
final class GitDiffHistoryFactory implements HistoryFactory |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* GitDiffHistoryFactory constructor. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( |
|
31
|
|
|
private GitWrapper $gitCliWrapper, |
|
32
|
|
|
private Parser $parser, |
|
33
|
|
|
) { |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws HistoryAnalyserException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function newHistoryAnalyser(HistoryMarker $baseLineHistoryMarker, ProjectRoot $projectRoot): HistoryAnalyser |
|
40
|
|
|
{ |
|
41
|
|
|
Assert::isInstanceOf($baseLineHistoryMarker, GitCommit::class); |
|
42
|
|
|
$diff = $this->gitCliWrapper->getGitDiff($projectRoot, $baseLineHistoryMarker); |
|
43
|
|
|
$fileMutations = $this->parser->parseDiff($diff); |
|
44
|
|
|
|
|
45
|
|
|
return new DiffHistoryAnalyser($fileMutations); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function newHistoryMarkerFactory(): HistoryMarkerFactory |
|
49
|
|
|
{ |
|
50
|
|
|
return new GitHistoryMarkerFactory($this->gitCliWrapper); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getIdentifier(): string |
|
54
|
|
|
{ |
|
55
|
|
|
return 'git'; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|