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\ResultsParser; |
14
|
|
|
|
15
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\BaseLiner\BaseLineAnalysisResult; |
16
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\Location; |
17
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\Severity; |
18
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\Type; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Holds a single result from the static analysis results. |
22
|
|
|
*/ |
23
|
|
|
class AnalysisResult |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Location |
27
|
|
|
*/ |
28
|
|
|
private $location; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Type |
32
|
|
|
*/ |
33
|
|
|
private $type; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $message; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
* @psalm-var array<mixed> |
43
|
|
|
*/ |
44
|
|
|
private $fullDetails; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var Severity |
48
|
|
|
*/ |
49
|
|
|
private $severity; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* AnalysisResult constructor. |
53
|
|
|
* |
54
|
|
|
* NOTE: $fullDetails should contain an array with all data from the original tool. |
55
|
|
|
* This allows tool specific output formatters to be written to output additional information if needed. |
56
|
|
|
* E.g. PHP-CS gives additional fields e.g. is_fixable. If this data needs to be shown to end user then |
57
|
|
|
* then a custom output formatter could be written to give all this additional information. |
58
|
|
|
* |
59
|
|
|
* @psalm-param array<mixed> $fullDetails |
60
|
|
|
*/ |
61
|
|
|
public function __construct(Location $location, Type $type, string $message, array $fullDetails, Severity $severity) |
62
|
|
|
{ |
63
|
|
|
$this->location = $location; |
64
|
|
|
$this->type = $type; |
65
|
|
|
$this->message = $message; |
66
|
|
|
$this->fullDetails = $fullDetails; |
67
|
|
|
$this->severity = $severity; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getLocation(): Location |
71
|
|
|
{ |
72
|
|
|
return $this->location; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getType(): Type |
76
|
|
|
{ |
77
|
|
|
return $this->type; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @psalm-return array<mixed> |
82
|
|
|
*/ |
83
|
|
|
public function getFullDetails(): array |
84
|
|
|
{ |
85
|
|
|
return $this->fullDetails; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getMessage(): string |
89
|
|
|
{ |
90
|
|
|
return $this->message; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getSeverity(): Severity |
94
|
|
|
{ |
95
|
|
|
return $this->severity; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function asBaseLineAnalysisResult(): BaseLineAnalysisResult |
99
|
|
|
{ |
100
|
|
|
return BaseLineAnalysisResult::make( |
101
|
|
|
$this->location->getRelativeFileName(), |
102
|
|
|
$this->location->getLineNumber(), |
103
|
|
|
$this->type, |
104
|
|
|
$this->message, |
105
|
|
|
$this->severity |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|