From 8d372188d44c7f89181e2bdb72a3f453337834d6 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 26 Apr 2018 13:40:30 +0200 Subject: [PATCH] make use of TypeAnalyzer->isPhpReservedType() instead of static method in PropretyNaming --- src/Builder/PropertyBuilder.php | 17 +++++++++++++---- src/Naming/PropertyNaming.php | 8 -------- src/Node/NodeFactory.php | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Builder/PropertyBuilder.php b/src/Builder/PropertyBuilder.php index 69e977366d5..a91ce8bf998 100644 --- a/src/Builder/PropertyBuilder.php +++ b/src/Builder/PropertyBuilder.php @@ -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 . '|'; } diff --git a/src/Naming/PropertyNaming.php b/src/Naming/PropertyNaming.php index 9605698aaca..b2895df434e 100644 --- a/src/Naming/PropertyNaming.php +++ b/src/Naming/PropertyNaming.php @@ -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); - } } diff --git a/src/Node/NodeFactory.php b/src/Node/NodeFactory.php index 276c9c5f804..0446320fc3c 100644 --- a/src/Node/NodeFactory.php +++ b/src/Node/NodeFactory.php @@ -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); }