Total Complexity | 9 |
Total Lines | 85 |
Duplicated Lines | 0 % |
Coverage | 82.61% |
Changes | 0 |
1 | <?php |
||
7 | class Stack |
||
8 | { |
||
9 | /** |
||
10 | * The parser stack for formulae. |
||
11 | * |
||
12 | * @var mixed[] |
||
13 | */ |
||
14 | private $stack = []; |
||
15 | |||
16 | /** |
||
17 | * Count of entries in the parser stack. |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | private $count = 0; |
||
22 | |||
23 | /** |
||
24 | * Return the number of entries on the stack. |
||
25 | * |
||
26 | * @return int |
||
27 | */ |
||
28 | 118 | public function count() |
|
29 | { |
||
30 | 118 | return $this->count; |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * Push a new entry onto the stack. |
||
35 | * |
||
36 | * @param mixed $type |
||
37 | * @param mixed $value |
||
38 | * @param mixed $reference |
||
39 | */ |
||
40 | 118 | public function push($type, $value, $reference = null) |
|
41 | { |
||
42 | 118 | $this->stack[$this->count++] = [ |
|
43 | 118 | 'type' => $type, |
|
44 | 118 | 'value' => $value, |
|
45 | 118 | 'reference' => $reference, |
|
46 | ]; |
||
47 | 118 | if ($type == 'Function') { |
|
48 | 46 | $localeFunction = Calculation::localeFunc($value); |
|
49 | 46 | if ($localeFunction != $value) { |
|
50 | $this->stack[($this->count - 1)]['localeValue'] = $localeFunction; |
||
51 | } |
||
52 | } |
||
53 | 118 | } |
|
54 | |||
55 | /** |
||
56 | * Pop the last entry from the stack. |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | 118 | public function pop() |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Return an entry from the stack without removing it. |
||
71 | * |
||
72 | * @param int $n number indicating how far back in the stack we want to look |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | 118 | public function last($n = 1) |
|
77 | { |
||
78 | 118 | if ($this->count - $n < 0) { |
|
79 | 111 | return null; |
|
80 | } |
||
81 | |||
82 | 117 | return $this->stack[$this->count - $n]; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Clear the stack. |
||
87 | */ |
||
88 | public function clear() |
||
92 | } |
||
93 | } |
||
94 |