Skip to content
Merged
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
32 changes: 4 additions & 28 deletions src/PhpParser/Comparing/NodeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,17 @@ public function printWithoutComments(Node|array|null $node): string
return trim($content);
}

/**
* @param Node|Node[]|null $firstNode
* @param Node|Node[]|null $secondNode
*/
public function areNodesEqual(Node|array|null $firstNode, Node|array|null $secondNode): bool
public function areNodesEqual(Node|null $firstNode, Node|null $secondNode): bool
{
if ($firstNode === null || $secondNode === null) {
if (! $firstNode instanceof Node || ! $secondNode instanceof Node) {
return false;
}

if ($firstNode instanceof Node && ! $secondNode instanceof Node) {
if ($firstNode::class !== $secondNode::class) {
return false;
}

if (! $firstNode instanceof Node && $secondNode instanceof Node) {
return false;
}

if (is_array($firstNode) && ! is_array($secondNode)) {
return false;
}

if (! is_array($secondNode)) {
if ($firstNode::class !== $secondNode::class) {
return false;
}

return $this->printWithoutComments($firstNode) === $this->printWithoutComments($secondNode);
}

if (is_array($firstNode)) {
return $this->printWithoutComments($firstNode) === $this->printWithoutComments($secondNode);
}

return false;
return $this->printWithoutComments($firstNode) === $this->printWithoutComments($secondNode);
}

/**
Expand Down
Loading