1 | <?php |
||
23 | final class AdjacentTextMerger |
||
24 | { |
||
25 | 2028 | public static function mergeChildNodes(Node $node) |
|
26 | { |
||
27 | // No children or just one child node, no need for merging |
||
28 | 2028 | if ($node->firstChild() === $node->lastChild() || $node->firstChild() === null || $node->lastChild() === null) { |
|
29 | 1218 | return; |
|
30 | } |
||
31 | |||
32 | 1038 | self::mergeTextNodesInclusive($node->firstChild(), $node->lastChild()); |
|
33 | 1038 | } |
|
34 | |||
35 | 417 | public static function mergeTextNodesBetweenExclusive(Node $fromNode, Node $toNode) |
|
36 | { |
||
37 | // No nodes between them |
||
38 | 417 | if ($fromNode === $toNode || $fromNode->next() === $toNode || $fromNode->next() === null || $toNode->previous() === null) { |
|
39 | 3 | return; |
|
40 | } |
||
41 | |||
42 | 417 | self::mergeTextNodesInclusive($fromNode->next(), $toNode->previous()); |
|
43 | 417 | } |
|
44 | |||
45 | 1212 | private static function mergeTextNodesInclusive(Node $fromNode, Node $toNode) |
|
70 | |||
71 | 1212 | private static function mergeIfNeeded(?Text $first, ?Text $last) |
|
91 | } |
||
92 |