Skip to content

Commit

Permalink
Refactor from PARENT_NODE in AddArrayDefaultToArrayPropertyRector (#3951
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TomasVotruba committed May 24, 2023
1 parent 49561b6 commit 2e80e00
Showing 1 changed file with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Rector\CodingStyle\TypeAnalyzer\IterableTypeAnalyzer;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -117,30 +116,27 @@ private function collectPropertyNamesWithMissingDefaultArray(Class_ $class): arr
{
$propertyNames = [];
$this->traverseNodesWithCallable($class, function (Node $node) use (&$propertyNames) {
if (! $node instanceof PropertyProperty) {
if (! $node instanceof Property) {
return null;
}

if ($node->default instanceof Expr) {
return null;
}
foreach ($node->props as $propertyProperty) {
if ($propertyProperty->default instanceof Expr) {
continue;
}

$varType = $this->resolveVarType($node);
if (! $this->iterableTypeAnalyzer->detect($varType)) {
return null;
}
$varType = $this->resolveVarType($node);
if (! $this->iterableTypeAnalyzer->detect($varType)) {
continue;
}

$property = $node->getAttribute(AttributeKey::PARENT_NODE);
if (! $property instanceof Property) {
return null;
}
if ($this->visibilityManipulator->isReadonly($node)) {
return null;
}

if ($this->visibilityManipulator->isReadonly($property)) {
return null;
$propertyNames[] = $this->getName($propertyProperty);
}

$propertyNames[] = $this->getName($node);

return null;
});

Expand Down Expand Up @@ -240,12 +236,10 @@ private function replaceNullComparisonOfArrayPropertiesWithArrayComparison(
});
}

private function resolveVarType(PropertyProperty $propertyProperty): Type
private function resolveVarType(Property $property): Type
{
/** @var Property $propertyNode */
$propertyNode = $propertyProperty->getAttribute(AttributeKey::PARENT_NODE);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);

$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($propertyNode);
return $phpDocInfo->getVarType();
}

Expand Down

0 comments on commit 2e80e00

Please sign in to comment.