mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
bdfd24339f
2e977bd3aa
deploy to original repository
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\ChangesReporting\ValueObject;
|
|
|
|
use Rector\Core\Contract\Rector\RectorInterface;
|
|
use RectorPrefix20220607\Symplify\EasyParallel\Contract\SerializableInterface;
|
|
use RectorPrefix20220607\Webmozart\Assert\Assert;
|
|
final class RectorWithLineChange implements SerializableInterface
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private const KEY_RECTOR_CLASS = 'rector_class';
|
|
/**
|
|
* @var string
|
|
*/
|
|
private const KEY_LINE = 'line';
|
|
/**
|
|
* @var class-string<RectorInterface>
|
|
* @readonly
|
|
*/
|
|
private $rectorClass;
|
|
/**
|
|
* @readonly
|
|
* @var int
|
|
*/
|
|
private $line;
|
|
/**
|
|
* @param string|\Rector\Core\Contract\Rector\RectorInterface $rectorClass
|
|
*/
|
|
public function __construct($rectorClass, int $line)
|
|
{
|
|
$this->line = $line;
|
|
if ($rectorClass instanceof RectorInterface) {
|
|
$rectorClass = \get_class($rectorClass);
|
|
}
|
|
$this->rectorClass = $rectorClass;
|
|
}
|
|
/**
|
|
* @return class-string<RectorInterface>
|
|
*/
|
|
public function getRectorClass() : string
|
|
{
|
|
return $this->rectorClass;
|
|
}
|
|
public function getLine() : int
|
|
{
|
|
return $this->line;
|
|
}
|
|
/**
|
|
* @param array<string, mixed> $json
|
|
* @return $this
|
|
*/
|
|
public static function decode(array $json) : \RectorPrefix20220607\Symplify\EasyParallel\Contract\SerializableInterface
|
|
{
|
|
$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>, line: int}
|
|
*/
|
|
public function jsonSerialize() : array
|
|
{
|
|
return [self::KEY_RECTOR_CLASS => $this->rectorClass, self::KEY_LINE => $this->line];
|
|
}
|
|
}
|