Test Failed
Push — master ( 16c39a...9c7d46 )
by Kirill
07:07
created

TypeNameNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toTypeName() 0 8 3
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\AST;
11
12
use Railt\Parser\Ast\LeafInterface;
13
use Railt\Parser\Ast\Rule;
14
use Railt\Parser\Ast\RuleInterface;
15
use Railt\SDL\Frontend\Type\AtGlobal;
16
use Railt\SDL\Frontend\Type\TypeName;
17
use Railt\SDL\Frontend\Type\TypeNameInterface;
18
19
/**
20
 * Class TypeNameNode
21
 */
22
class TypeNameNode extends Rule
23
{
24
    /**
25
     * @param bool $atRoot
26
     * @return TypeNameInterface
27
     */
28
    public function toTypeName(bool $atRoot = false): TypeNameInterface
29
    {
30
        if ($atRoot || $this->first('> #AtRoot') instanceof RuleInterface) {
31
            return new AtGlobal($this->getNameChunks());
32
        }
33
34
        return new TypeName($this->getNameChunks());
35
    }
36
37
    /**
38
     * @return array|string[]
39
     */
40
    private function getNameChunks(): array
41
    {
42
        $result = [];
43
44
        /** @var LeafInterface $leaf */
45
        foreach ($this->find(':T_NAME') as $leaf) {
46
            $result[] = $leaf->getValue();
47
        }
48
49
        return $result;
50
    }
51
}
52