Test Setup Failed
Push — master ( 1595cb...1df194 )
by Kirill
02:11
created

HashTableFacadeTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 59
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasVariable() 0 3 1
A bootHashTableFacadeTrait() 0 5 1
A findVariable() 0 7 2
A addVariable() 0 5 1
A getVariables() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of Railt package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Railt\SDL\Compiler;
13
14
use Railt\SDL\Backend\HashTable;
15
use Railt\SDL\Backend\HashTableInterface;
16
use Railt\TypeSystem\Value\ValueInterface;
17
18
/**
19
 * Trait HashTableFacadeTrait
20
 */
21
trait HashTableFacadeTrait
22
{
23
    use ValueFactoryFacadeTrait;
24
25
    /**
26
     * @var HashTableInterface
27
     */
28
    protected HashTableInterface $hash;
29
30
    /**
31
     * @return void
32
     */
33
    private function bootHashTableFacadeTrait(): void
34
    {
35
        $this->bootValueFactoryFacadeTrait();
36
37
        $this->hash = new HashTable($this->factory);
38
    }
39
40
    /**
41
     * @return HashTableInterface
42
     */
43
    public function getVariables(): HashTableInterface
44
    {
45
        return $this->hash;
46
    }
47
48
    /**
49
     * @param string $name
50
     * @param $value
51
     * @return $this
52
     */
53
    public function addVariable(string $name, $value): self
54
    {
55
        $this->hash->add($name, $value);
56
57
        return $this;
58
    }
59
60
    /**
61
     * @param string $name
62
     * @return ValueInterface|null
63
     */
64
    public function findVariable(string $name): ?ValueInterface
65
    {
66
        if ($this->hash->has($name)) {
67
            return $this->hash->get($name);
68
        }
69
70
        return null;
71
    }
72
73
    /**
74
     * @param string $name
75
     * @return bool
76
     */
77
    public function hasVariable(string $name): bool
78
    {
79
        return $this->hash->has($name);
80
    }
81
}
82