Skip to content

refactor(HTMLNode): Deprecate duplicate methods and rename applyClass #68

@usernane

Description

@usernane

Description

Several methods are exact delegates with no added logic. These should be consolidated by deprecating the redundant ones and pointing users to the canonical method.

Deprecations

Deprecate Keep (canonical) Reason
getAttributeValue($name) getAttribute($name) Exact delegate, standard DOM naming
addTextNode($txt, $esc) text($txt, $esc) Exact delegate, fluent pattern consistent with br(), hr(), comment()
addCommentNode($txt) comment($txt) Exact delegate, same fluent pattern
component($path, $vals) include($path, $vals) Exact delegate, already marked deprecated in source
getName() getAttribute('name') Trivial shortcut, confusing next to getNodeName()
setName($val) setAttribute('name', $val) Trivial shortcut, confusing next to setNodeName()
applyClass($cName, $override) applyClassToChildren($cName, $override, $depth) Misleading name (see below)

Removals (dead code)

Remove Reason
private $null property Unused, assigned null in constructor, never read
isUseOriginalText() Already @deprecated, no internal references
$useOriginalTxt property Only supports the deprecated method above

Keep Both (no deprecation)

Method Reason
count() Required by Countable interface for count($node)
childrenCount() Explicit named method, different use case

New Method: applyClassToChildren()

applyClass() applies a class to all children, not to the node itself. The name is misleading. Replace with:

public function applyClassToChildren(string $cName, bool $override = true, int $depth = 1): HTMLNode {
    if ($depth < 1) {
        return $this;
    }
    foreach ($this as $child) {
        $child->setClassName($cName, $override);
        if ($depth > 1 && !$child->isVoidNode()) {
            $child->applyClassToChildren($cName, $override, $depth - 1);
        }
    }
    return $this;
}
  • $depth = 1 — direct children only (default, matches current behavior)
  • $depth = 2 — children + grandchildren
  • $depth = PHP_INT_MAX — all descendants

Acceptance Criteria

  • Deprecated methods have @deprecated tag pointing to the canonical method
  • Deprecated methods still function (no removal yet)
  • applyClassToChildren() added with $depth parameter
  • Dead code ($null, isUseOriginalText(), $useOriginalTxt) removed
  • All 308 tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions