Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TemplateModeStack
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 push
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 pop
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isEmpty
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\RemexHtml\TreeBuilder;
5
6/**
7 * The stack of template insertion modes. We use a storage model optimised for
8 * access to the element at the top of the stack, which is stored separately
9 * from the rest of the stack.
10 */
11class TemplateModeStack {
12    /**
13     * The insertion mode at the top of the stack. This is public for
14     * performance reasons but should be treated as read-only.
15     * @var int|null
16     */
17    public $current;
18
19    /**
20     * The remainder of the stack
21     *
22     * @var array
23     */
24    private $nonCurrentModes = [];
25
26    /**
27     * Push a mode on to the stack
28     * @param int $mode
29     */
30    public function push( $mode ) {
31        $this->nonCurrentModes[] = $this->current;
32        $this->current = $mode;
33    }
34
35    /**
36     * Pop a mode from the stack
37     */
38    public function pop() {
39        $this->current = array_pop( $this->nonCurrentModes );
40    }
41
42    /**
43     * Return true if the stack is empty, false otherwise
44     * @return bool
45     */
46    public function isEmpty() {
47        return $this->current === null;
48    }
49}