Debian Codegraph @

vendor/wikimedia/parsoid/src/Ext/DiffDOMUtils.php

raw
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Wikimedia\Parsoid\Ext;
5
6 use Wikimedia\Parsoid\DOM\Node;
7 use Wikimedia\Parsoid\Utils\DiffDOMUtils as DDU;
8
9 /**
10 */
11 class DiffDOMUtils {
12
13 /**
14 * Test the number of children this node has without using
15 * `DOMNode::$childNodes->count()`. This walks the sibling list and so
16 * takes O(`nchildren`) time -- so `nchildren` is expected to be small
17 * (say: 0, 1, or 2).
18 *
19 * Skips all diff markers by default.
20 * @param Node $node
21 * @param int $nchildren
22 * @param bool $countDiffMarkers
23 * @return bool
24 */
25 public static function hasNChildren(
26 Node $node, int $nchildren, bool $countDiffMarkers = false
27 ): bool {
28 return DDU::hasNChildren( $node, $nchildren, $countDiffMarkers );
29 }
30
31 /**
32 * Get the first child element or non-IEW text node, ignoring
33 * whitespace-only text nodes, comments, and deleted nodes.
34 *
35 * @param Node $node
36 * @return Node|null
37 */
38 public static function firstNonSepChild( Node $node ): ?Node {
39 return DDU::firstNonSepChild( $node );
40 }
41
42 /**
43 * Get the next non separator sibling node.
44 *
45 * @param Node $node
46 * @return Node|null
47 */
48 public static function nextNonSepSibling( Node $node ): ?Node {
49 return DDU::nextNonSepSibling( $node );
50 }
51
52 }