Skip to content

Consolidate the sibling and ancestor traversal loops in QueryFilters into one helper #115

Closed

Description

@gravitypdf-bot

Follow-up from the /simplify pass on #72. Assumes #72 is merged.

Problem

The sibling and ancestor traversals in src/Helpers/QueryFilters.php are each a hand-written copy of the same loop, differing only in the DOM property they walk and whether they stop at the first match:

Methods Axis Shape
nextAll() / prevAll() nextSibling / previousSibling collect, then filter the set
next() / prev() nextSibling / previousSibling stop at first match
nextUntil() / prevUntil() nextSibling / previousSibling collect until a match
parents() / parent() / parentsUntil() parentNode all three shapes
siblings() both collect, then filter

#72 had to make the same edit in every one of them, which is the cost of this layout: a fix to one is easily missed in its mirror.

Proposal

One private helper that walks an axis and applies the shape, e.g.

private function walk(string $axis, ?string $selector, string $mode): SplObjectStorage
// $axis: 'nextSibling' | 'previousSibling' | 'parentNode'
// $mode: 'all' | 'first' | 'until'

The public methods become one-line calls. PHP 7.1 compatible ($m->{$axis}).

This should be a pure refactor: the existing tests (including Issue62Test) must pass unchanged. Ordering is tracked separately in the jQuery-ordering issue.

Activity

  1. added a commit that references this issue on Oct 26, 2026
    4fec833
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions