SymbolStack::isEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\Stack;
6
7
use Remorhaz\UniLex\Exception;
8
9
class SymbolStack implements PushInterface
10
{
11
    /**
12
     * @var StackableSymbolInterface[]
13
     */
14
    private $data = [];
15
16
    /**
17
     * @return StackableSymbolInterface
18
     * @throws Exception
19
     */
20
    public function pop(): StackableSymbolInterface
21
    {
22
        if (empty($this->data)) {
23
            throw new Exception("Unexpected end of stack");
24
        }
25
        return array_pop($this->data);
26
    }
27
28
    public function push(StackableSymbolInterface ...$symbolList): void
29
    {
30
        if (empty($symbolList)) {
31
            return;
32
        }
33
        array_push($this->data, ...array_reverse($symbolList));
34
    }
35
36
    public function isEmpty(): bool
37
    {
38
        return empty($this->data);
39
    }
40
41
    public function reset(): void
42
    {
43
        $this->data = [];
44
    }
45
}
46