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
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
getAttributeValue($name)getAttribute($name)addTextNode($txt, $esc)text($txt, $esc)br(),hr(),comment()addCommentNode($txt)comment($txt)component($path, $vals)include($path, $vals)getName()getAttribute('name')getNodeName()setName($val)setAttribute('name', $val)setNodeName()applyClass($cName, $override)applyClassToChildren($cName, $override, $depth)Removals (dead code)
private $nullpropertynullin constructor, never readisUseOriginalText()@deprecated, no internal references$useOriginalTxtpropertyKeep Both (no deprecation)
count()Countableinterface forcount($node)childrenCount()New Method:
applyClassToChildren()applyClass()applies a class to all children, not to the node itself. The name is misleading. Replace with:$depth = 1— direct children only (default, matches current behavior)$depth = 2— children + grandchildren$depth = PHP_INT_MAX— all descendantsAcceptance Criteria
@deprecatedtag pointing to the canonical methodapplyClassToChildren()added with$depthparameter$null,isUseOriginalText(),$useOriginalTxt) removed