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