Completed
Push — master ( cb3635...aae171 )
by Дмитрий
03:10
created

SymbolTable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 44
ccs 0
cts 12
cp 0
rs 10
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A get() 0 8 2
A count() 0 4 1
A clear() 0 4 1
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Compiler;
7
8
use Countable;
9
use PHPSA\Variable;
10
11
class SymbolTable implements Countable
12
{
13
    /**
14
     * @var Variable[]
15
     */
16
    protected $variables = [];
17
18
    /**
19
     * @param Variable $variable
20
     */
21
    public function add(Variable $variable)
22
    {
23
        $this->variables[$variable->getName()] = $variable;
24
    }
25
26
    /**
27
     * @param string $name
28
     * @return Variable|null
29
     */
30
    public function get($name)
31
    {
32
        if (isset($this->variables[$name])) {
33
            return $this->variables[$name];
34
        }
35
36
        return null;
37
    }
38
39
    /**
40
     * @return int
41
     */
42
    public function count()
43
    {
44
        return count($this->variables);
45
    }
46
47
    /**
48
     * Clear symbol table
49
     */
50
    public function clear()
51
    {
52
        $this->variables = [];
53
    }
54
}
55