|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Domain\BaseLiner; |
|
6
|
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\FileName; |
|
8
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\LineNumber; |
|
9
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\Location; |
|
10
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\Type; |
|
11
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils\ArrayParseException; |
|
12
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils\ArrayUtils; |
|
13
|
|
|
|
|
14
|
|
|
class BaseLineAnalysisResult |
|
15
|
|
|
{ |
|
16
|
|
|
private const LINE_NUMBER = 'lineNumber'; |
|
17
|
|
|
private const FILE_NAME = 'fileName'; |
|
18
|
|
|
private const TYPE = 'type'; |
|
19
|
|
|
private const MESSAGE = 'message'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var FileName |
|
23
|
|
|
*/ |
|
24
|
|
|
private $fileName; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var LineNumber |
|
27
|
|
|
*/ |
|
28
|
|
|
private $lineNumber; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var Type |
|
31
|
|
|
*/ |
|
32
|
|
|
private $type; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $message; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @phpstan-param array<mixed> $array |
|
40
|
|
|
* |
|
41
|
|
|
* @throws ArrayParseException |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function fromArray(array $array): self |
|
44
|
|
|
{ |
|
45
|
|
|
$lineNumber = new LineNumber(ArrayUtils::getIntValue($array, self::LINE_NUMBER)); |
|
46
|
|
|
$fileName = new FileName(ArrayUtils::getStringValue($array, self::FILE_NAME)); |
|
47
|
|
|
$type = new Type(ArrayUtils::getStringValue($array, self::TYPE)); |
|
48
|
|
|
$message = ArrayUtils::getStringValue($array, self::MESSAGE); |
|
49
|
|
|
|
|
50
|
|
|
return new self($fileName, $lineNumber, $type, $message); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public static function make( |
|
54
|
|
|
FileName $fileName, |
|
55
|
|
|
LineNumber $lineNumber, |
|
56
|
|
|
Type $type, |
|
57
|
|
|
string $message |
|
58
|
|
|
): self { |
|
59
|
|
|
return new self($fileName, $lineNumber, $type, $message); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
private function __construct(FileName $fileName, LineNumber $lineNumber, Type $type, string $message) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->fileName = $fileName; |
|
65
|
|
|
$this->lineNumber = $lineNumber; |
|
66
|
|
|
$this->type = $type; |
|
67
|
|
|
$this->message = $message; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getFileName(): FileName |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->fileName; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getLineNumber(): LineNumber |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->lineNumber; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getType(): Type |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->type; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getMessage(): string |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->message; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @phpstan-return array<string,string|int> |
|
92
|
|
|
*/ |
|
93
|
|
|
public function asArray(): array |
|
94
|
|
|
{ |
|
95
|
|
|
return [ |
|
96
|
|
|
self::LINE_NUMBER => $this->getLineNumber()->getLineNumber(), |
|
97
|
|
|
self::FILE_NAME => $this->getFileName()->getFileName(), |
|
98
|
|
|
self::TYPE => $this->type->getType(), |
|
99
|
|
|
self::MESSAGE => $this->message, |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Return true if this matches matches given FileName, LineNumber and type. |
|
105
|
|
|
*/ |
|
106
|
|
|
public function isMatch(Location $location, Type $type): bool |
|
107
|
|
|
{ |
|
108
|
|
|
return |
|
109
|
|
|
$this->fileName->isEqual($location->getFileName()) && |
|
110
|
|
|
$this->lineNumber->isEqual($location->getLineNumber()) && |
|
111
|
|
|
$this->type->isEqual($type); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|