Completed
Pull Request — master (#325)
by Enrico
02:57
created

SymbolTable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 35.7%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 52
ccs 5
cts 14
cp 0.357
rs 10
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A count() 0 4 1
A clear() 0 4 1
A getVariables() 0 4 1
A add() 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 1
    public function add(Variable $variable)
22
    {
23 1
        $this->variables[$variable->getName()] = $variable;
24 1
    }
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
    /**
56
     * @return Variable[]
57
     */
58 1
    public function getVariables()
59
    {
60 1
        return $this->variables;
61
    }
62
}
63