Test Failed
Push — master ( b7ab7b...94ee03 )
by Kirill
02:59
created

TypeNameBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 4 1
A reduce() 0 4 1
A getTypeName() 0 6 1
A getNameChunks() 0 11 2
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\Frontend\Builder\Common;
11
12
use Railt\Parser\Ast\LeafInterface;
13
use Railt\Parser\Ast\RuleInterface;
14
use Railt\SDL\Frontend\Builder\BaseBuilder;
15
use Railt\SDL\Frontend\Context\ContextInterface;
16
use Railt\SDL\IR\SymbolTable\TypeNamePrimitive;
17
use Railt\SDL\IR\SymbolTable\Value;
18
use Railt\SDL\IR\SymbolTable\ValueInterface;
19
use Railt\SDL\IR\Type;
20
use Railt\SDL\IR\Type\Name;
21
use Railt\SDL\IR\Type\TypeNameInterface;
22
23
/**
24
 * Class TypeNameBuilder
25
 */
26
class TypeNameBuilder extends BaseBuilder
27
{
28
    /**
29
     * @param RuleInterface $rule
30
     * @return bool
31
     */
32
    public function match(RuleInterface $rule): bool
33
    {
34
        return $rule->getName() === 'TypeName';
35
    }
36
37
    /**
38
     * @param ContextInterface $ctx
39
     * @param RuleInterface $rule
40
     * @return TypeNameInterface
41
     */
42
    public function reduce(ContextInterface $ctx, RuleInterface $rule): TypeNameInterface
43
    {
44
        return $this->getTypeName($rule);
45
    }
46
47
    /**
48
     * @param RuleInterface $rule
49
     * @return TypeNameInterface
50
     */
51
    protected function getTypeName(RuleInterface $rule): TypeNameInterface
52
    {
53
        $atRoot = $rule->first('> #AtRoot') instanceof RuleInterface;
54
55
        return Name::fromArray($this->getNameChunks($rule), $atRoot);
56
    }
57
58
    /**
59
     * @param RuleInterface $rule
60
     * @return array|string[]
61
     */
62
    private function getNameChunks(RuleInterface $rule): array
63
    {
64
        $result = [];
65
66
        /** @var LeafInterface $leaf */
67
        foreach ($rule->find('> :T_NAME') as $leaf) {
68
            $result[] = $leaf->getValue();
69
        }
70
71
        return $result;
72
    }
73
}
74