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