mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 04:03:55 +01:00
make use of TypeAnalyzer->isPhpReservedType() instead of static method in PropretyNaming
This commit is contained in:
parent
9e48370e10
commit
8d372188d4
@ -7,7 +7,7 @@ use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property as PhpParserProperty;
|
||||
use Rector\Builder\Class_\VariableInfo;
|
||||
use Rector\Naming\PropertyNaming;
|
||||
use Rector\Php\TypeAnalyzer;
|
||||
|
||||
final class PropertyBuilder
|
||||
{
|
||||
@ -21,10 +21,19 @@ final class PropertyBuilder
|
||||
*/
|
||||
private $statementGlue;
|
||||
|
||||
public function __construct(BuilderFactory $builderFactory, StatementGlue $statementGlue)
|
||||
{
|
||||
/**
|
||||
* @var TypeAnalyzer
|
||||
*/
|
||||
private $typeAnalyzer;
|
||||
|
||||
public function __construct(
|
||||
BuilderFactory $builderFactory,
|
||||
StatementGlue $statementGlue,
|
||||
TypeAnalyzer $typeAnalyzer
|
||||
) {
|
||||
$this->builderFactory = $builderFactory;
|
||||
$this->statementGlue = $statementGlue;
|
||||
$this->typeAnalyzer = $typeAnalyzer;
|
||||
}
|
||||
|
||||
public function addPropertyToClass(Class_ $classNode, VariableInfo $variableInfo): void
|
||||
@ -81,7 +90,7 @@ final class PropertyBuilder
|
||||
{
|
||||
$implodedTypes = '';
|
||||
foreach ($propertyTypes as $propertyType) {
|
||||
$implodedTypes .= PropertyNaming::isPhpReservedType($propertyType)
|
||||
$implodedTypes .= $this->typeAnalyzer->isPhpReservedType($propertyType)
|
||||
? $propertyType
|
||||
: '\\' . $propertyType . '|';
|
||||
}
|
||||
|
@ -24,12 +24,4 @@ final class PropertyNaming
|
||||
|
||||
return lcfirst($camelCaseName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo use TypeAnalyzer instead
|
||||
*/
|
||||
public static function isPhpReservedType(string $type): bool
|
||||
{
|
||||
return in_array($type, ['string', 'bool', 'mixed', 'object', 'iterable', 'array'], true);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\TraitUse;
|
||||
use Rector\Builder\Class_\VariableInfo;
|
||||
use Rector\Exception\NotImplementedException;
|
||||
use Rector\Naming\PropertyNaming;
|
||||
use Rector\Php\TypeAnalyzer;
|
||||
|
||||
final class NodeFactory
|
||||
{
|
||||
@ -40,10 +40,19 @@ final class NodeFactory
|
||||
*/
|
||||
private $propertyFetchNodeFactory;
|
||||
|
||||
public function __construct(BuilderFactory $builderFactory, PropertyFetchNodeFactory $propertyFetchNodeFactory)
|
||||
{
|
||||
/**
|
||||
* @var TypeAnalyzer
|
||||
*/
|
||||
private $typeAnalyzer;
|
||||
|
||||
public function __construct(
|
||||
BuilderFactory $builderFactory,
|
||||
PropertyFetchNodeFactory $propertyFetchNodeFactory,
|
||||
TypeAnalyzer $typeAnalyzer
|
||||
) {
|
||||
$this->builderFactory = $builderFactory;
|
||||
$this->propertyFetchNodeFactory = $propertyFetchNodeFactory;
|
||||
$this->typeAnalyzer = $typeAnalyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,7 +238,7 @@ final class NodeFactory
|
||||
|
||||
public function createTypeName(string $name): Name
|
||||
{
|
||||
if (PropertyNaming::isPhpReservedType($name)) {
|
||||
if ($this->typeAnalyzer->isPhpReservedType($name)) {
|
||||
return new Name($name);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user