2020-09-17 23:18:18 +02:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\Naming\ValueObject;
|
2020-09-17 23:18:18 +02:00
|
|
|
|
2024-11-20 19:59:31 +00:00
|
|
|
use PhpParser\Node\PropertyItem;
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node\Stmt\ClassLike;
|
|
|
|
use PhpParser\Node\Stmt\Property;
|
2024-01-02 02:40:38 +00:00
|
|
|
use Rector\Validation\RectorAssert;
|
2024-06-18 08:34:51 +00:00
|
|
|
final class PropertyRename
|
2020-09-17 23:18:18 +02:00
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-09-17 23:18:18 +02:00
|
|
|
*/
|
2024-11-20 15:58:53 +00:00
|
|
|
private Property $property;
|
2020-09-17 23:18:18 +02:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-09-17 23:18:18 +02:00
|
|
|
*/
|
2024-11-20 15:58:53 +00:00
|
|
|
private string $expectedName;
|
2020-09-28 20:29:37 +02:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-09-28 20:29:37 +02:00
|
|
|
*/
|
2024-11-20 15:58:53 +00:00
|
|
|
private string $currentName;
|
2020-09-17 23:18:18 +02:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-09-17 23:18:18 +02:00
|
|
|
*/
|
2024-11-20 15:58:53 +00:00
|
|
|
private ClassLike $classLike;
|
2020-09-17 23:18:18 +02:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-09-17 23:18:18 +02:00
|
|
|
*/
|
2024-11-20 15:58:53 +00:00
|
|
|
private string $classLikeName;
|
2020-09-17 23:18:18 +02:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2020-09-17 23:18:18 +02:00
|
|
|
*/
|
2024-11-20 15:58:53 +00:00
|
|
|
private PropertyItem $propertyItem;
|
|
|
|
public function __construct(Property $property, string $expectedName, string $currentName, ClassLike $classLike, string $classLikeName, PropertyItem $propertyItem)
|
2021-05-09 20:15:43 +00:00
|
|
|
{
|
2020-09-17 23:18:18 +02:00
|
|
|
$this->property = $property;
|
|
|
|
$this->expectedName = $expectedName;
|
|
|
|
$this->currentName = $currentName;
|
|
|
|
$this->classLike = $classLike;
|
2020-09-28 20:29:37 +02:00
|
|
|
$this->classLikeName = $classLikeName;
|
2024-11-20 15:58:53 +00:00
|
|
|
$this->propertyItem = $propertyItem;
|
2022-07-16 09:41:53 +00:00
|
|
|
// name must be valid
|
|
|
|
RectorAssert::propertyName($currentName);
|
|
|
|
RectorAssert::propertyName($expectedName);
|
2020-09-17 23:18:18 +02:00
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
public function getProperty() : Property
|
2020-09-17 23:18:18 +02:00
|
|
|
{
|
|
|
|
return $this->property;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function isPrivateProperty() : bool
|
2020-11-16 17:50:38 +00:00
|
|
|
{
|
|
|
|
return $this->property->isPrivate();
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getExpectedName() : string
|
2020-09-17 23:18:18 +02:00
|
|
|
{
|
|
|
|
return $this->expectedName;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getCurrentName() : string
|
2020-09-17 23:18:18 +02:00
|
|
|
{
|
|
|
|
return $this->currentName;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function isAlreadyExpectedName() : bool
|
2021-03-01 01:56:08 +01:00
|
|
|
{
|
|
|
|
return $this->currentName === $this->expectedName;
|
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
public function getClassLike() : ClassLike
|
2020-09-17 23:18:18 +02:00
|
|
|
{
|
2020-09-21 22:45:43 +02:00
|
|
|
return $this->classLike;
|
2020-09-17 23:18:18 +02:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getClassLikeName() : string
|
2020-09-28 20:29:37 +02:00
|
|
|
{
|
|
|
|
return $this->classLikeName;
|
|
|
|
}
|
2024-11-20 15:58:53 +00:00
|
|
|
public function getPropertyProperty() : PropertyItem
|
2020-09-17 23:18:18 +02:00
|
|
|
{
|
2024-11-20 15:58:53 +00:00
|
|
|
return $this->propertyItem;
|
2020-09-17 23:18:18 +02:00
|
|
|
}
|
|
|
|
}
|