Skip to content

Commit

Permalink
Remove PREVIOUS_STATEMENT from SimplifyUselessVariableRector (#2127)
Browse files Browse the repository at this point in the history
* misc

* remove vague definition of visual similarity, better resolve by case manually

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Apr 23, 2022
1 parent dd2b376 commit 7bc7426
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 87 deletions.
2 changes: 0 additions & 2 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_STATEMENT,
\Rector\NodeTypeResolver\Node\AttributeKey::USE_NODES,
\Rector\NodeTypeResolver\Node\AttributeKey::START_TOKEN_POSITION,
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE,
Expand All @@ -74,7 +73,6 @@
\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_STATEMENT,
\Rector\NodeTypeResolver\Node\AttributeKey::USE_NODES,
\Rector\NodeTypeResolver\Node\AttributeKey::START_TOKEN_POSITION,
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Rector\Core\NodeAnalyzer\VariableAnalyzer;
use Rector\Core\PhpParser\Node\AssignAndBinaryMap;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -154,10 +153,6 @@ private function shouldSkipStmt(Return_ $return, Stmt $previousStmt): bool
return true;
}

if ($this->isPreviousExpressionVisuallySimilar($previousStmt, $previousNode)) {
return true;
}

if ($this->variableAnalyzer->isStaticOrGlobal($variable)) {
return true;
}
Expand All @@ -183,20 +178,4 @@ private function isReturnWithVarAnnotation(Return_ $return): bool
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($return);
return ! $phpDocInfo->getVarType() instanceof MixedType;
}

private function isPreviousExpressionVisuallySimilar(
Expression $previousExpression,
AssignOp | Assign $previousNode
): bool {
$prePreviousExpression = $previousExpression->getAttribute(AttributeKey::PREVIOUS_STATEMENT);
if (! $prePreviousExpression instanceof Expression) {
return false;
}

if (! $prePreviousExpression->expr instanceof AssignOp) {
return false;
}

return $this->nodeComparator->areNodesEqual($prePreviousExpression->expr->var, $previousNode->var);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ function (array $matches): string {

$output .= isset($matches[1]) ? strtolower($matches[1]) : '';
$output .= $matches[2] ?? '';
$output .= $matches[3] ?? '';

return $output;
return $output . ($matches[3] ?? '');
}
);
$objectType = new ObjectType($newVariableName);
Expand Down

0 comments on commit 7bc7426

Please sign in to comment.