Test Setup Failed
Push — master ( 1595cb...050b68 )
by Kirill
21:00
created

DefinitionContext::typeOf()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
cc 4
nc 4
nop 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\Backend\Context;
13
14
use Phplrt\Visitor\Traverser;
15
use Railt\SDL\Backend\Context\Support\DescriptionReaderTrait;
16
use Railt\SDL\Backend\Context\Support\TypeReferenceTrait;
17
use Railt\SDL\Backend\Context\Support\ValueTrait;
18
use Railt\SDL\Backend\HashTable\VariablesVisitor;
19
use Railt\SDL\Backend\HashTableInterface;
20
use Railt\SDL\Frontend\Ast\DefinitionNode;
21
22
/**
23
 * Class DefinitionContext
24
 */
25
abstract class DefinitionContext implements DefinitionContextInterface
26
{
27
    use ValueTrait;
28
    use TypeReferenceTrait;
0 ignored issues
show
introduced by
The trait Railt\SDL\Backend\Contex...port\TypeReferenceTrait requires some properties which are not provided by Railt\SDL\Backend\Context\DefinitionContext: $type, $name, $value, $arguments
Loading history...
29
    use DescriptionReaderTrait;
0 ignored issues
show
Bug introduced by
The trait Railt\SDL\Backend\Contex...\DescriptionReaderTrait requires the property $description which is not provided by Railt\SDL\Backend\Context\DefinitionContext.
Loading history...
30
31
    /**
32
     * @var DefinitionNode
33
     */
34
    protected DefinitionNode $ast;
35
36
    /**
37
     * @var Factory
38
     */
39
    private Factory $factory;
40
41
    /**
42
     * DefinitionContext constructor.
43
     *
44
     * @param HashTableInterface $vars
45
     * @param Factory $factory
46
     * @param DefinitionNode $ast
47
     */
48
    public function __construct(HashTableInterface $vars, Factory $factory, DefinitionNode $ast)
49
    {
50
        $this->factory = $factory;
51
        $this->ast = $this->prebuild($vars, $ast);
52
    }
53
54
    /**
55
     * @param HashTableInterface $vars
56
     * @param DefinitionNode $ast
57
     * @return DefinitionNode|iterable
58
     */
59
    private function prebuild(HashTableInterface $vars, DefinitionNode $ast): DefinitionNode
60
    {
61
        $traverser = new Traverser([
62
            new VariablesVisitor($vars),
63
        ]);
64
65
        return $traverser->traverse($ast);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $traverser->traverse($ast) returns the type iterable which is incompatible with the type-hinted return Railt\SDL\Frontend\Ast\DefinitionNode.
Loading history...
66
    }
67
68
    /**
69
     * @return Factory
70
     */
71
    protected function getFactory(): Factory
72
    {
73
        return $this->factory;
74
    }
75
}
76