Completed
Push — master ( 8afd90...4bf010 )
by Kirill
03:48
created

Builder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler\Builder;
11
12
use Railt\Parser\Ast\RuleInterface;
13
use Railt\Reflection\Contracts\Definition;
14
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesTypeIndication;
15
use Railt\Reflection\Contracts\Definition\TypeDefinition;
16
use Railt\SDL\Compiler\Ast\Value\ValueInterface;
17
use Railt\SDL\Compiler\Builder\Common\ValueBuilder;
18
use Railt\SDL\Compiler\Factory;
19
use Railt\SDL\Compiler\Pipeline;
20
21
/**
22
 * Class Builder
23
 */
24
abstract class Builder implements BuilderInterface
25
{
26
    /**
27
     * @var Pipeline
28
     */
29
    protected $when;
30
31
    /**
32
     * @var Factory
33
     */
34
    private $factory;
35
36
    /**
37
     * Builder constructor.
38
     * @param Pipeline $pipeline
39
     * @param Factory $factory
40
     */
41 1
    public function __construct(Pipeline $pipeline, Factory $factory)
42
    {
43 1
        $this->when = $pipeline;
44 1
        $this->factory = $factory;
45 1
    }
46
47
    /**
48
     * @param Definition|ProvidesTypeIndication $from
49
     * @param ValueInterface $value
50
     * @return array|mixed
51
     * @throws \Railt\Io\Exception\ExternalFileException
52
     */
53
    protected function valueOf(ProvidesTypeIndication $from, ValueInterface $value)
54
    {
55
        return (new ValueBuilder($from))->valueOf($value);
56
    }
57
58
    /**
59
     * @param string $type
60
     * @param TypeDefinition $from
61
     * @return TypeDefinition
62
     * @throws \Railt\Reflection\Exception\TypeNotFoundException
63
     */
64
    protected function load(string $type, TypeDefinition $from): TypeDefinition
65
    {
66
        $dict = $from->getDictionary();
67
68
        return $dict->get($type, $from);
69
    }
70
71
    /**
72
     * @param RuleInterface $ast
73
     * @param Definition $parent
74
     * @return Definition
75
     * @throws \Railt\Io\Exception\ExternalFileException
76
     */
77
    protected function dependent(RuleInterface $ast, Definition $parent): Definition
78
    {
79
        return $this->factory->build($ast, $parent);
80
    }
81
}
82