2021-01-18 10:44:07 +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\NodeFactory;
|
2021-01-18 10:44:07 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node\Expr\PropertyFetch;
|
|
|
|
use PhpParser\Node\Expr\Variable;
|
|
|
|
use PHPStan\Type\ObjectType;
|
|
|
|
use Rector\Naming\Naming\PropertyNaming;
|
2021-01-18 10:44:07 +00:00
|
|
|
final class PropertyFetchFactory
|
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var \Rector\Naming\Naming\PropertyNaming
|
2021-01-18 10:44:07 +00:00
|
|
|
*/
|
|
|
|
private $propertyNaming;
|
2022-06-07 08:22:29 +00:00
|
|
|
public function __construct(PropertyNaming $propertyNaming)
|
2021-01-18 10:44:07 +00:00
|
|
|
{
|
|
|
|
$this->propertyNaming = $propertyNaming;
|
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
public function createFromType(ObjectType $objectType) : PropertyFetch
|
2021-01-18 10:44:07 +00:00
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
$thisVariable = new Variable('this');
|
2021-02-28 07:47:48 +00:00
|
|
|
$propertyName = $this->propertyNaming->fqnToVariableName($objectType->getClassName());
|
2022-06-07 08:22:29 +00:00
|
|
|
return new PropertyFetch($thisVariable, $propertyName);
|
2021-01-18 10:44:07 +00:00
|
|
|
}
|
|
|
|
}
|