Repository navigation
Expand file tree
/
Copy pathRectorWithLineChange.php
More file actions
65 lines (53 loc) · 1.56 KB
/
Copy pathRectorWithLineChange.php
File metadata and controls
65 lines (53 loc) · 1.56 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
<?php
declare(strict_types=1);
namespace Rector\ChangesReporting\ValueObject;
use Rector\Contract\Rector\RectorInterface;
use Rector\Parallel\Contract\SerializableInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Webmozart\Assert\Assert;
final readonly class RectorWithLineChange implements SerializableInterface
{
private const string KEY_RECTOR_CLASS = 'rector_class';
private const string KEY_LINE = 'line';
/**
* @param class-string<RectorInterface|PostRectorInterface> $rectorClass
*/
public function __construct(
private string $rectorClass,
private int $line
) {
}
/**
* @return class-string<RectorInterface|PostRectorInterface>
*/
public function getRectorClass(): string
{
return $this->rectorClass;
}
public function getLine(): int
{
return $this->line;
}
/**
* @param array<string, mixed> $json
*/
public static function decode(array $json): self
{
/** @var class-string<RectorInterface> $rectorClass */
$rectorClass = $json[self::KEY_RECTOR_CLASS];
Assert::string($rectorClass);
$line = $json[self::KEY_LINE];
Assert::integer($line);
return new self($rectorClass, $line);
}
/**
* @return array{rector_class: class-string<RectorInterface|PostRectorInterface>, line: int}
*/
public function jsonSerialize(): array
{
return [
self::KEY_RECTOR_CLASS => $this->rectorClass,
self::KEY_LINE => $this->line,
];
}
}