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 * @license GPL-2.0-or-later
4 * @file
5 * @ingroup Parser
6 */
7
8namespace MediaWiki\Parser;
9
10use RuntimeException;
11
12/**
13 * Stack class to help Preprocessor::preprocessToObj()
14 * @ingroup Parser
15 */
16// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
17class PPDStack_Hash {
18    /** @var PPDStackElement_Hash[] */
19    public $stack;
20    /** @var string[] */
21    public $rootAccum;
22    /** @var string[] */
23    public $accum;
24
25    /**
26     * @var PPDStackElement_Hash|false
27     */
28    public $top;
29    /** @var string|null */
30    public $out;
31    /** @var class-string<PPDStackElement_Hash> */
32    public $elementClass = PPDStackElement_Hash::class;
33
34    public function __construct() {
35        $this->stack = [];
36        $this->top = false;
37        $this->rootAccum = [];
38        $this->accum =& $this->rootAccum;
39    }
40
41    /**
42     * @return int
43     */
44    public function count() {
45        return count( $this->stack );
46    }
47
48    /** @return string[] */
49    public function &getAccum() {
50        return $this->accum;
51    }
52
53    /**
54     * @return false|PPDPart_Hash
55     */
56    public function getCurrentPart() {
57        if ( $this->top === false ) {
58            return false;
59        } else {
60            return $this->top->getCurrentPart();
61        }
62    }
63
64    /**
65     * @param PPDStackElement_Hash|array $data
66     */
67    public function push( $data ) {
68        if ( $data instanceof $this->elementClass ) {
69            $this->stack[] = $data;
70        } else {
71            $class = $this->elementClass;
72            $this->stack[] = new $class( $data );
73        }
74        $this->top = $this->stack[count( $this->stack ) - 1];
75        $this->accum =& $this->top->getAccum();
76    }
77
78    /** @return PPDStackElement_Hash */
79    public function pop() {
80        if ( $this->stack === [] ) {
81            throw new RuntimeException( __METHOD__ . ': no elements remaining' );
82        }
83        $temp = array_pop( $this->stack );
84
85        if ( count( $this->stack ) ) {
86            $this->top = $this->stack[count( $this->stack ) - 1];
87            $this->accum =& $this->top->getAccum();
88        } else {
89            $this->top = false;
90            $this->accum =& $this->rootAccum;
91        }
92        return $temp;
93    }
94
95    /**
96     * @param string $s
97     */
98    public function addPart( $s = '' ) {
99        $this->top->addPart( $s );
100        $this->accum =& $this->top->getAccum();
101    }
102
103    /**
104     * @return array
105     */
106    public function getFlags() {
107        if ( $this->stack === [] ) {
108            return [
109                'findEquals' => false,
110                'findPipe' => false,
111                'inHeading' => false,
112            ];
113        } else {
114            return $this->top->getFlags();
115        }
116    }
117}
118
119/** @deprecated class alias since 1.43 */
120class_alias( PPDStack_Hash::class, 'PPDStack_Hash' );