Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
30 / 33
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
22/**
23 * Stack class to help Preprocessor::preprocessToObj()
24 * @ingroup Parser
25 */
26// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
27class PPDStack_Hash {
28    /** @var PPDStackElement_Hash[] */
29    public $stack;
30    /** @var string[] */
31    public $rootAccum;
32    /** @var string[] */
33    public $accum;
34
35    /**
36     * @var PPDStackElement_Hash|false
37     */
38    public $top;
39    public $out;
40    public $elementClass = PPDStackElement_Hash::class;
41
42    public static $false = false;
43
44    public function __construct() {
45        $this->stack = [];
46        $this->top = false;
47        $this->rootAccum = [];
48        $this->accum =& $this->rootAccum;
49    }
50
51    /**
52     * @return int
53     */
54    public function count() {
55        return count( $this->stack );
56    }
57
58    public function &getAccum() {
59        return $this->accum;
60    }
61
62    /**
63     * @return false|PPDPart_Hash
64     */
65    public function getCurrentPart() {
66        if ( $this->top === false ) {
67            return false;
68        } else {
69            return $this->top->getCurrentPart();
70        }
71    }
72
73    public function push( $data ) {
74        if ( $data instanceof $this->elementClass ) {
75            $this->stack[] = $data;
76        } else {
77            $class = $this->elementClass;
78            $this->stack[] = new $class( $data );
79        }
80        $this->top = $this->stack[count( $this->stack ) - 1];
81        $this->accum =& $this->top->getAccum();
82    }
83
84    public function pop() {
85        if ( $this->stack === [] ) {
86            throw new RuntimeException( __METHOD__ . ': no elements remaining' );
87        }
88        $temp = array_pop( $this->stack );
89
90        if ( count( $this->stack ) ) {
91            $this->top = $this->stack[count( $this->stack ) - 1];
92            $this->accum =& $this->top->getAccum();
93        } else {
94            $this->top = self::$false;
95            $this->accum =& $this->rootAccum;
96        }
97        return $temp;
98    }
99
100    public function addPart( $s = '' ) {
101        $this->top->addPart( $s );
102        $this->accum =& $this->top->getAccum();
103    }
104
105    /**
106     * @return array
107     */
108    public function getFlags() {
109        if ( $this->stack === [] ) {
110            return [
111                'findEquals' => false,
112                'findPipe' => false,
113                'inHeading' => false,
114            ];
115        } else {
116            return $this->top->getFlags();
117        }
118    }
119}