Skip to content

Commit

Permalink
refactor: correct nested check in replace_shuffled_indices
Browse files Browse the repository at this point in the history
This worked, but only by accident. The $ancestor !== $indexelement was useless.

See: questionpy-org/questionpy-sdk#141 (comment)
  • Loading branch information
MHajoha committed Dec 3, 2024
1 parent 46a1a6e commit 41e2359
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions classes/question_ui_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ private function hide_unwanted_feedback(): void {
private function shuffle_contents(): void {
/** @var DOMElement $element */
foreach (iterator_to_array($this->xpath->query('//*[@qpy:shuffle-contents]')) as $element) {
$element->removeAttributeNS(constants::NAMESPACE_QPY, 'shuffle-contents');
$newelement = $element->cloneNode();

// We want to shuffle elements while leaving other nodes (such as text, spacing) where they are.
Expand All @@ -181,6 +180,7 @@ private function shuffle_contents(): void {
}
}

$newelement->removeAttributeNS(constants::NAMESPACE_QPY, 'shuffle-contents');
$element->parentNode->replaceChild($newelement, $element);
}
}
Expand All @@ -197,7 +197,7 @@ private function replace_shuffled_indices(DOMNode $element, int $index): void {
foreach (iterator_to_array($this->xpath->query('.//qpy:shuffled-index', $element)) as $indexelement) {
// phpcs:ignore Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterSecond
for (
$ancestor = $indexelement->parentNode; $ancestor !== null && $ancestor !== $indexelement;
$ancestor = $indexelement->parentNode; $ancestor !== null && $ancestor !== $element;
$ancestor = $ancestor->parentNode
) {
assert($ancestor instanceof DOMElement);
Expand Down

0 comments on commit 41e2359

Please sign in to comment.