Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rules/dead-code/src/NodeManipulator/CountManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ private function isCountWithExpression(Node $node, Expr $expr): bool

$countedExpr = $node->args[0]->value;

return $this->betterStandardPrinter->areNodesWithoutCommentsEqual($countedExpr, $expr);
return $this->betterStandardPrinter->areNodesEqual($countedExpr, $expr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private function areArgsAndParamsEqual(array $args, array $params): bool

$param = $params[$key];

if (! $this->areNodesWithoutCommentsEqual($param->var, $arg->value)) {
if (! $this->areNodesEqual($param->var, $arg->value)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private function shouldRemoveAssignNode(
$isVariableAssigned = (bool) $this->betterNodeFinder->findFirst($assignNode->expr, function (Node $node) use (
$nodeByTypeAndPosition
): bool {
return $this->areNodesWithoutCommentsEqual($node, $nodeByTypeAndPosition->getVariableNode());
return $this->areNodesEqual($node, $nodeByTypeAndPosition->getVariableNode());
});

return ! $isVariableAssigned;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function getParameterOverlap(array $parameters1, array $parameters2): ar
$parameters1,
$parameters2,
function (Param $firstParam, Param $secondParam): int {
return $this->areNodesWithoutCommentsEqual($firstParam, $secondParam) ? 0 : 1;
return $this->areNodesEqual($firstParam, $secondParam) ? 0 : 1;
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->areNodesWithoutCommentsEqual($onlyCatch->var, $onlyCatchStmt->expr)) {
if (! $this->areNodesEqual($onlyCatch->var, $onlyCatchStmt->expr)) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions rules/dead-code/src/UselessIfCondBeforeForeachDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function isMatchingNotEmpty(If_ $if, Expr $foreachExpr): bool
/** @var Empty_ $empty */
$empty = $cond->expr;

return $this->betterStandardPrinter->areNodesWithoutCommentsEqual($empty->expr, $foreachExpr);
return $this->betterStandardPrinter->areNodesEqual($empty->expr, $foreachExpr);
}

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ private function isEmptyArrayAndForeachedVariable(Expr $leftExpr, Expr $rightExp
return false;
}

return $this->betterStandardPrinter->areNodesWithoutCommentsEqual($foreachExpr, $rightExpr);
return $this->betterStandardPrinter->areNodesEqual($foreachExpr, $rightExpr);
}

private function isEmptyArray(Expr $expr): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function isReturnTypeAlreadyAdded(FunctionLike $functionLike, Type $retur
}

$returnNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType);
if ($this->betterStandardPrinter->areNodesWithoutCommentsEqual($nodeReturnType, $returnNode)) {
if ($this->betterStandardPrinter->areNodesEqual($nodeReturnType, $returnNode)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/Node/Manipulator/ClassMethodManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function isParameterUsedInClassMethod(Param $param, ClassMethod $classMet
$isUsedDirectly = (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) use (
$param
): bool {
return $this->betterStandardPrinter->areNodesWithoutCommentsEqual($node, $param->var);
return $this->betterStandardPrinter->areNodesEqual($node, $param->var);
});

if ($isUsedDirectly) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/Node/Manipulator/VariableManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function isReadOnlyVariable(ClassMethod $classMethod, Variable $variable
return false;
}

return $this->betterStandardPrinter->areNodesWithoutCommentsEqual($node, $variable);
return $this->betterStandardPrinter->areNodesEqual($node, $variable);
});

foreach ($variableUsages as $variableUsage) {
Expand Down
11 changes: 2 additions & 9 deletions src/PhpParser/Printer/BetterStandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,12 @@ public function print($node): string
}

/**
* Removes all comments from both nodes
*
* @param Node|Node[]|null $firstNode
* @param Node|Node[]|null $secondNode
*/
public function areNodesEqual($firstNode, $secondNode): bool
{
return $this->print($firstNode) === $this->print($secondNode);
}

/**
* @param Node|Node[]|null $firstNode
* @param Node|Node[]|null $secondNode
*/
public function areNodesWithoutCommentsEqual($firstNode, $secondNode): bool
{
return $this->printWithoutComments($firstNode) === $this->printWithoutComments($secondNode);
}
Expand Down
13 changes: 3 additions & 10 deletions src/Rector/AbstractRector/BetterStandardPrinterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function printToFile($node, string $filePath): void
}

/**
* Removes all comments from both nodes
*
* @param Node|Node[]|null $firstNode
* @param Node|Node[]|null $secondNode
*/
Expand All @@ -71,15 +73,6 @@ protected function areNodesEqual($firstNode, $secondNode): bool
return $this->betterStandardPrinter->areNodesEqual($firstNode, $secondNode);
}

/**
* @param Node|Node[]|null $firstNode
* @param Node|Node[]|null $secondNode
*/
protected function areNodesWithoutCommentsEqual($firstNode, $secondNode): bool
{
return $this->betterStandardPrinter->areNodesWithoutCommentsEqual($firstNode, $secondNode);
}

/**
* @param Node[] $availableNodes
*/
Expand All @@ -94,7 +87,7 @@ protected function isNodeEqual(Node $singleNode, array $availableNodes): bool
$availableNode = clone $availableNode;
$availableNode->setAttribute('comments', null);

if ($this->areNodesWithoutCommentsEqual($singleNode, $availableNode)) {
if ($this->areNodesEqual($singleNode, $availableNode)) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rector/AbstractRector/ComplexRemovalTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private function removeConstructorDependency(Assign $assign): void
}

foreach ($constructClassMethod->getParams() as $param) {
if (! $this->betterStandardPrinter->areNodesWithoutCommentsEqual($param->var, $assign->expr)) {
if (! $this->betterStandardPrinter->areNodesEqual($param->var, $assign->expr)) {
continue;
}

Expand Down