2020-08-26 10:54:53 +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\Transform\ValueObject;
|
2020-08-26 10:54:53 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PHPStan\Type\ObjectType;
|
2024-01-02 02:40:38 +00:00
|
|
|
use Rector\Validation\RectorAssert;
|
2021-01-28 23:32:20 +00:00
|
|
|
final class PropertyFetchToMethodCall
|
2020-08-26 10:54:53 +00:00
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-08-26 10:54:53 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $oldType;
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-08-26 10:54:53 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $oldProperty;
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-08-26 10:54:53 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $newGetMethod;
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-08-26 10:54:53 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
2021-05-12 13:15:45 +00:00
|
|
|
private $newSetMethod;
|
2021-05-10 23:39:21 +00:00
|
|
|
/**
|
|
|
|
* @var mixed[]
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-05-10 23:39:21 +00:00
|
|
|
*/
|
2021-05-11 10:40:34 +00:00
|
|
|
private $newGetArguments = [];
|
2020-10-11 14:17:43 +00:00
|
|
|
/**
|
|
|
|
* @param mixed[] $newGetArguments
|
|
|
|
*/
|
2021-05-09 20:15:43 +00:00
|
|
|
public function __construct(string $oldType, string $oldProperty, string $newGetMethod, ?string $newSetMethod = null, array $newGetArguments = [])
|
|
|
|
{
|
2020-08-26 10:54:53 +00:00
|
|
|
$this->oldType = $oldType;
|
|
|
|
$this->oldProperty = $oldProperty;
|
|
|
|
$this->newGetMethod = $newGetMethod;
|
|
|
|
$this->newSetMethod = $newSetMethod;
|
|
|
|
$this->newGetArguments = $newGetArguments;
|
2022-06-07 08:22:29 +00:00
|
|
|
RectorAssert::className($oldType);
|
2022-07-16 09:41:53 +00:00
|
|
|
RectorAssert::propertyName($oldProperty);
|
|
|
|
RectorAssert::methodName($newGetMethod);
|
|
|
|
if (\is_string($newSetMethod)) {
|
|
|
|
RectorAssert::methodName($newSetMethod);
|
|
|
|
}
|
2020-08-26 10:54:53 +00:00
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
public function getOldObjectType() : ObjectType
|
2020-08-26 10:54:53 +00:00
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
return new ObjectType($this->oldType);
|
2020-08-26 10:54:53 +00:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getOldProperty() : string
|
2020-08-26 10:54:53 +00:00
|
|
|
{
|
|
|
|
return $this->oldProperty;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getNewGetMethod() : string
|
2020-08-26 10:54:53 +00:00
|
|
|
{
|
|
|
|
return $this->newGetMethod;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getNewSetMethod() : ?string
|
2020-08-26 10:54:53 +00:00
|
|
|
{
|
|
|
|
return $this->newSetMethod;
|
|
|
|
}
|
2020-09-01 17:56:30 +00:00
|
|
|
/**
|
|
|
|
* @return mixed[]
|
|
|
|
*/
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getNewGetArguments() : array
|
2020-08-26 10:54:53 +00:00
|
|
|
{
|
|
|
|
return $this->newGetArguments;
|
|
|
|
}
|
|
|
|
}
|