1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Legacy; |
6
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\ResultsParser\InvalidResultsParserException; |
8
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\ResultsParser\ResultsParser; |
9
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils\FqcnRemover; |
10
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\ExakatJsonResultsParser\ExakatJsonResultsParser; |
11
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\PhanJsonResultsParser\PhanJsonResultsParser; |
12
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\PhpCodeSnifferJsonResultsParser\PhpCodeSnifferJsonResultsParser; |
13
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\PhpmdJsonResultsParser\PhpmdJsonResultsParser; |
14
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\PhpstanJsonResultsParser\PhpstanJsonResultsParser; |
15
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\PsalmJsonResultsParser\PsalmJsonResultsParser; |
16
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\ResultsParsers\SarbJsonResultsParser\SarbJsonResultsParser; |
17
|
|
|
|
18
|
|
|
class LegacyResultsParserConverter |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var FqcnRemover |
22
|
|
|
*/ |
23
|
|
|
private $fqcnRemover; |
24
|
|
|
|
25
|
|
|
public function __construct(FqcnRemover $fqcnRemover) |
26
|
|
|
{ |
27
|
|
|
$this->fqcnRemover = $fqcnRemover; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** @throws InvalidResultsParserException */ |
31
|
|
|
public function getNewResultsParser(string $legacyResultsParserIdentifier): ResultsParser |
32
|
|
|
{ |
33
|
|
|
/** @var array<string,ResultsParser> */ |
34
|
|
|
$lookup = [ |
35
|
|
|
'exakat-sarb' => new ExakatJsonResultsParser(), |
36
|
|
|
'phan-json' => new PhanJsonResultsParser(), |
37
|
|
|
'phpcodesniffer-full' => new PhpCodeSnifferJsonResultsParser(), |
38
|
|
|
'phpcodesniffer-json' => new PhpCodeSnifferJsonResultsParser(), |
39
|
|
|
'phpmd-json' => new PhpmdJsonResultsParser(), |
40
|
|
|
'phpstan-json-tmp' => new PhpstanJsonResultsParser($this->fqcnRemover), |
41
|
|
|
'phpstan-text-tmp' => new PhpstanJsonResultsParser($this->fqcnRemover), |
42
|
|
|
'psalm-json' => new PsalmJsonResultsParser(), |
43
|
|
|
'psalm-text-tmp' => new PsalmJsonResultsParser(), |
44
|
|
|
'sarb-json' => new SarbJsonResultsParser(), |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
$resultsParser = $lookup[$legacyResultsParserIdentifier] ?? null; |
48
|
|
|
|
49
|
|
|
if (null === $resultsParser) { |
50
|
|
|
throw InvalidResultsParserException::invalidIdentifier($legacyResultsParserIdentifier); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $resultsParser; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|