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

TypeNameNode::getNameChunks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 11
rs 9.9
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\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