Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.24% covered (warning)
88.24%
30 / 34
62.50% covered (warning)
62.50%
5 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
PPDStack_Hash
90.91% covered (success)
90.91%
30 / 33
62.50% covered (warning)
62.50%
5 / 8
13.13
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 count
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAccum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCurrentPart
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 push
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 pop
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
3.01
 addPart
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFlags
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Parser
20 */
21
22namespace MediaWiki\Parser;
23
24use RuntimeException;
25
26/**
27 * Stack class to help Preprocessor::preprocessToObj()
28 * @ingroup Parser
29 */
30// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
31class PPDStack_Hash {
32    /** @var PPDStackElement_Hash[] */
33    public $stack;
34    /** @var string[] */
35    public $rootAccum;
36    /** @var string[] */
37    public $accum;
38
39    /**
40     * @var PPDStackElement_Hash|false
41     */
42    public $top;
43    /** @var string|null */
44    public $out;
45    /** @var string */
46    public $elementClass = PPDStackElement_Hash::class;
47
48    public function __construct() {
49        $this->stack = [];
50        $this->top = false;
51        $this->rootAccum = [];
52        $this->accum =& $this->rootAccum;
53    }
54
55    /**
56     * @return int
57     */
58    public function count() {
59        return count( $this->stack );
60    }
61
62    public function &getAccum() {
63        return $this->accum;
64    }
65
66    /**
67     * @return false|PPDPart_Hash
68     */
69    public function getCurrentPart() {
70        if ( $this->top === false ) {
71            return false;
72        } else {
73            return $this->top->getCurrentPart();
74        }
75    }
76
77    public function push( $data ) {
78        if ( $data instanceof $this->elementClass ) {
79            $this->stack[] = $data;
80        } else {
81            $class = $this->elementClass;
82            $this->stack[] = new $class( $data );
83        }
84        $this->top = $this->stack[count( $this->stack ) - 1];
85        $this->accum =& $this->top->getAccum();
86    }
87
88    public function pop() {
89        if ( $this->stack === [] ) {
90            throw new RuntimeException( __METHOD__ . ': no elements remaining' );
91        }
92        $temp = array_pop( $this->stack );
93
94        if ( count( $this->stack ) ) {
95            $this->top = $this->stack[count( $this->stack ) - 1];
96            $this->accum =& $this->top->getAccum();
97        } else {
98            $this->top = false;
99            $this->accum =& $this->rootAccum;
100        }
101        return $temp;
102    }
103
104    public function addPart( $s = '' ) {
105        $this->top->addPart( $s );
106        $this->accum =& $this->top->getAccum();
107    }
108
109    /**
110     * @return array
111     */
112    public function getFlags() {
113        if ( $this->stack === [] ) {
114            return [
115                'findEquals' => false,
116                'findPipe' => false,
117                'inHeading' => false,
118            ];
119        } else {
120            return $this->top->getFlags();
121        }
122    }
123}
124
125/** @deprecated class alias since 1.43 */
126class_alias( PPDStack_Hash::class, 'PPDStack_Hash' );