make use of TypeAnalyzer->isPhpReservedType() instead of static method in PropretyNaming

This commit is contained in:
Tomas Votruba 2018-04-26 13:40:30 +02:00
parent 9e48370e10
commit 8d372188d4
3 changed files with 26 additions and 16 deletions

View File

@ -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 . '|';
}

View File

@ -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);
}
}

View File

@ -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);
}