-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathSystemError.php
More file actions
93 lines (78 loc) · 2.21 KB
/
SystemError.php
File metadata and controls
93 lines (78 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
namespace Rector\ValueObject\Error;
use Nette\Utils\Strings;
use Rector\Parallel\ValueObject\BridgeItem;
use Symplify\EasyParallel\Contract\SerializableInterface;
final readonly class SystemError implements SerializableInterface
{
public function __construct(
private string $message,
private string|null $relativeFilePath = null,
private int|null $line = null,
private string|null $rectorClass = null
) {
}
public function getMessage(): string
{
return $this->message;
}
public function getLine(): int|null
{
return $this->line;
}
public function getRelativeFilePath(): ?string
{
return $this->relativeFilePath;
}
public function getAbsoluteFilePath(): ?string
{
if ($this->relativeFilePath === null) {
return null;
}
return \realpath($this->relativeFilePath);
}
/**
* @return array{
* message: string,
* relative_file_path: string|null,
* absolute_file_path: string|null,
* line: int|null,
* rector_class: string|null
* }
*/
public function jsonSerialize(): array
{
return [
BridgeItem::MESSAGE => $this->message,
BridgeItem::RELATIVE_FILE_PATH => $this->relativeFilePath,
BridgeItem::ABSOLUTE_FILE_PATH => $this->getAbsoluteFilePath(),
BridgeItem::LINE => $this->line,
BridgeItem::RECTOR_CLASS => $this->rectorClass,
];
}
/**
* @param array<string, mixed> $json
*/
public static function decode(array $json): self
{
return new self(
$json[BridgeItem::MESSAGE],
$json[BridgeItem::RELATIVE_FILE_PATH],
$json[BridgeItem::LINE],
$json[BridgeItem::RECTOR_CLASS]
);
}
public function getRectorClass(): ?string
{
return $this->rectorClass;
}
public function getRectorShortClass(): ?string
{
$rectorClass = $this->rectorClass;
if (! in_array($rectorClass, [null, ''], true)) {
return (string) Strings::after($rectorClass, '\\', -1);
}
return null;
}
}