Symbol::getSymbol()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\AST;
6
7
use Remorhaz\UniLex\Exception;
8
use Remorhaz\UniLex\Stack\StackableSymbolInterface;
9
10
class Symbol implements StackableSymbolInterface
11
{
12
    private $header;
13
14
    private $index;
15
16
    private $symbol;
17
18
    public function __construct(Node $header, int $index)
19
    {
20
        $this->header = $header;
21
        $this->index = $index;
22
    }
23
24
    public function setSymbol(Node $node): void
25
    {
26
        $this->symbol = $node;
27
    }
28
29
    public function getHeader(): Node
30
    {
31
        return $this->header;
32
    }
33
34
    public function getIndex(): int
35
    {
36
        return $this->index;
37
    }
38
39
    /**
40
     * @return Node
41
     * @throws Exception
42
     */
43
    public function getSymbol(): Node
44
    {
45
        if (!isset($this->symbol)) {
46
            $this->symbol = $this
47
                ->getHeader()
48
                ->getChild($this->getIndex());
49
        }
50
        return $this->symbol;
51
    }
52
}
53