Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 15 |
CRAP | |
0.00% |
0 / 1 |
| Stack | |
0.00% |
0 / 22 |
|
0.00% |
0 / 15 |
20 | |
0.00% |
0 / 1 |
| push | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| pop | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| replace | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| remove | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| isInScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| isElementInScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| isOneOfSetInScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| isInListScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| isInButtonScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| isInTableScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| isInSelectScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| item | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| length | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| hasTemplate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
| dump | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml\TreeBuilder; |
| 5 | |
| 6 | /** |
| 7 | * The parent class for the "stack of open elements". |
| 8 | * @see CachingStack |
| 9 | * @see SimpleStack |
| 10 | */ |
| 11 | abstract class Stack { |
| 12 | /** @var Element|null */ |
| 13 | public $current; |
| 14 | |
| 15 | /** |
| 16 | * Push an element |
| 17 | * |
| 18 | * @param Element $elt |
| 19 | */ |
| 20 | abstract public function push( Element $elt ); |
| 21 | |
| 22 | /** |
| 23 | * Pop an element from the stack |
| 24 | * |
| 25 | * @return Element|null |
| 26 | */ |
| 27 | abstract public function pop(); |
| 28 | |
| 29 | /** |
| 30 | * Replace an element which is on the stack with another element of the |
| 31 | * same type (i.e. with the same tag name). |
| 32 | * |
| 33 | * @param Element $old The element to be removed |
| 34 | * @param Element $new The element to be inserted |
| 35 | */ |
| 36 | abstract public function replace( Element $old, Element $new ); |
| 37 | |
| 38 | /** |
| 39 | * Remove an element, potentially from the middle of the stack. |
| 40 | * |
| 41 | * @param Element $elt |
| 42 | */ |
| 43 | abstract public function remove( Element $elt ); |
| 44 | |
| 45 | /** |
| 46 | * Is there an element in (default) scope which is in the HTML namespace |
| 47 | * and has the given tag name? |
| 48 | * |
| 49 | * @param string $name |
| 50 | * @return bool |
| 51 | */ |
| 52 | abstract public function isInScope( $name ); |
| 53 | |
| 54 | /** |
| 55 | * Is the given element in (default) scope? |
| 56 | * |
| 57 | * @param Element $elt |
| 58 | * @return bool |
| 59 | */ |
| 60 | abstract public function isElementInScope( Element $elt ); |
| 61 | |
| 62 | /** |
| 63 | * Is there any element in the (default) scope which is in the HTML |
| 64 | * namespace and has one of the given tag names? |
| 65 | * |
| 66 | * @param array<string,mixed> $names An array with the tag names in the |
| 67 | * keys, the value arbitrary |
| 68 | * @return bool |
| 69 | */ |
| 70 | abstract public function isOneOfSetInScope( $names ); |
| 71 | |
| 72 | /** |
| 73 | * Is there an element in list scope which is an HTML element with the |
| 74 | * given name? |
| 75 | * |
| 76 | * @param string $name |
| 77 | * @return bool |
| 78 | */ |
| 79 | abstract public function isInListScope( $name ); |
| 80 | |
| 81 | /** |
| 82 | * Is there an element in button scope which is an HTML element with the |
| 83 | * given name? |
| 84 | * |
| 85 | * @param string $name |
| 86 | * @return bool |
| 87 | */ |
| 88 | abstract public function isInButtonScope( $name ); |
| 89 | |
| 90 | /** |
| 91 | * Is there an element in table scope which is an HTML element with the |
| 92 | * given name? |
| 93 | * |
| 94 | * @param string $name |
| 95 | * @return bool |
| 96 | */ |
| 97 | abstract public function isInTableScope( $name ); |
| 98 | |
| 99 | /** |
| 100 | * Is there an element in select scope which is an HTML element with the |
| 101 | * given name? |
| 102 | * |
| 103 | * @param string $name |
| 104 | * @return bool |
| 105 | */ |
| 106 | abstract public function isInSelectScope( $name ); |
| 107 | |
| 108 | /** |
| 109 | * Get an element from the stack, where 0 is the first element inserted, |
| 110 | * and $this->length() - 1 is the most recently inserted element. This will |
| 111 | * raise a PHP notice if the index is out of range. |
| 112 | * |
| 113 | * @param int $idx |
| 114 | * @return Element|null |
| 115 | */ |
| 116 | abstract public function item( $idx ); |
| 117 | |
| 118 | /** |
| 119 | * Get the number of elements in the stack. |
| 120 | * |
| 121 | * @return int |
| 122 | */ |
| 123 | abstract public function length(); |
| 124 | |
| 125 | /** |
| 126 | * Is there a template element in the stack of open elements? |
| 127 | * |
| 128 | * @return bool |
| 129 | */ |
| 130 | abstract public function hasTemplate(); |
| 131 | |
| 132 | /** |
| 133 | * Get a string representation of the stack for debugging purposes. |
| 134 | * |
| 135 | * @return string |
| 136 | */ |
| 137 | public function dump() { |
| 138 | $s = ''; |
| 139 | for ( $i = 0; $i < $this->length(); $i++ ) { |
| 140 | $item = $this->item( $i ); |
| 141 | $s .= "$i. " . $item->getDebugTag(); |
| 142 | if ( $i === $this->length() - 1 && $item !== $this->current ) { |
| 143 | $s .= " CURRENT POINTER INCORRECT"; |
| 144 | } |
| 145 | $s .= "\n"; |
| 146 | } |
| 147 | return $s; |
| 148 | } |
| 149 | } |