2021-04-13 00:12:48 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\ChangesReporting\ValueObject;
|
2021-04-13 00:12:48 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use Rector\Core\Contract\Rector\RectorInterface;
|
2023-05-01 01:36:32 +00:00
|
|
|
use RectorPrefix202305\Symplify\EasyParallel\Contract\SerializableInterface;
|
|
|
|
use RectorPrefix202305\Webmozart\Assert\Assert;
|
2022-06-07 08:22:29 +00:00
|
|
|
final class RectorWithLineChange implements SerializableInterface
|
2021-04-13 00:12:48 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-11-07 14:41:05 +00:00
|
|
|
* @var string
|
2021-04-13 00:12:48 +00:00
|
|
|
*/
|
2021-11-07 14:41:05 +00:00
|
|
|
private const KEY_RECTOR_CLASS = 'rector_class';
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private const KEY_LINE = 'line';
|
|
|
|
/**
|
|
|
|
* @var class-string<RectorInterface>
|
2021-12-04 12:47:17 +00:00
|
|
|
* @readonly
|
2021-11-07 14:41:05 +00:00
|
|
|
*/
|
|
|
|
private $rectorClass;
|
2021-04-13 00:12:48 +00:00
|
|
|
/**
|
2021-12-04 12:47:17 +00:00
|
|
|
* @readonly
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var int
|
2021-04-13 00:12:48 +00:00
|
|
|
*/
|
2021-05-10 23:39:21 +00:00
|
|
|
private $line;
|
2021-11-07 14:41:05 +00:00
|
|
|
/**
|
2022-04-26 08:13:18 +00:00
|
|
|
* @param string|\Rector\Core\Contract\Rector\RectorInterface $rectorClass
|
2021-11-07 14:41:05 +00:00
|
|
|
*/
|
|
|
|
public function __construct($rectorClass, int $line)
|
2021-04-13 00:12:48 +00:00
|
|
|
{
|
|
|
|
$this->line = $line;
|
2022-06-07 08:22:29 +00:00
|
|
|
if ($rectorClass instanceof RectorInterface) {
|
2021-11-07 14:41:05 +00:00
|
|
|
$rectorClass = \get_class($rectorClass);
|
|
|
|
}
|
|
|
|
$this->rectorClass = $rectorClass;
|
2021-04-13 00:12:48 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @return class-string<RectorInterface>
|
|
|
|
*/
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getRectorClass() : string
|
2021-04-13 00:12:48 +00:00
|
|
|
{
|
2021-11-07 14:41:05 +00:00
|
|
|
return $this->rectorClass;
|
2021-04-13 00:12:48 +00:00
|
|
|
}
|
2021-11-07 14:41:05 +00:00
|
|
|
/**
|
|
|
|
* @param array<string, mixed> $json
|
2022-01-17 11:11:59 +00:00
|
|
|
* @return $this
|
2021-11-07 14:41:05 +00:00
|
|
|
*/
|
2023-05-01 01:36:32 +00:00
|
|
|
public static function decode(array $json) : \RectorPrefix202305\Symplify\EasyParallel\Contract\SerializableInterface
|
2021-11-07 14:41:05 +00:00
|
|
|
{
|
2021-12-28 12:08:43 +00:00
|
|
|
$rectorClass = $json[self::KEY_RECTOR_CLASS];
|
2022-06-07 08:22:29 +00:00
|
|
|
Assert::string($rectorClass);
|
2021-12-28 12:08:43 +00:00
|
|
|
$line = $json[self::KEY_LINE];
|
2022-06-07 08:22:29 +00:00
|
|
|
Assert::integer($line);
|
2021-12-28 12:08:43 +00:00
|
|
|
return new self($rectorClass, $line);
|
2021-11-07 14:41:05 +00:00
|
|
|
}
|
|
|
|
/**
|
2022-03-07 11:34:50 +00:00
|
|
|
* @return array{rector_class: class-string<RectorInterface>, line: int}
|
2021-11-07 14:41:05 +00:00
|
|
|
*/
|
|
|
|
public function jsonSerialize() : array
|
|
|
|
{
|
|
|
|
return [self::KEY_RECTOR_CLASS => $this->rectorClass, self::KEY_LINE => $this->line];
|
|
|
|
}
|
2021-04-13 00:12:48 +00:00
|
|
|
}
|