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

ValueFactoryFacadeTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A cast() 0 3 1
A addValueCaster() 0 5 1
A getValueFactory() 0 3 1
A bootValueFactoryFacadeTrait() 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\ValueFactory;
15
use Railt\SDL\Frontend\Ast\Node;
16
use Railt\TypeSystem\Value\ValueInterface;
17
18
/**
19
 * Trait ValueFactoryFacadeTrait
20
 */
21
trait ValueFactoryFacadeTrait
22
{
23
    /**
24
     * @var ValueFactory
25
     */
26
    protected ValueFactory $factory;
27
28
    /**
29
     * @return void
30
     */
31
    private function bootValueFactoryFacadeTrait(): void
32
    {
33
        $this->factory = new ValueFactory();
34
    }
35
36
    /**
37
     * @return ValueFactory
38
     */
39
    public function getValueFactory(): ValueFactory
40
    {
41
        return $this->factory;
42
    }
43
44
    /**
45
     * @param \Closure $caster
46
     * @param bool $append
47
     * @return $this
48
     */
49
    public function addValueCaster(\Closure $caster, bool $append = true): self
50
    {
51
        $this->factory->addCaster($caster, $append);
52
53
        return $this;
54
    }
55
56
    /**
57
     * @param mixed $value
58
     * @return ValueInterface
59
     */
60
    public function cast($value): ValueInterface
61
    {
62
        return $this->factory->make($value);
63
    }
64
}
65