Test Failed
Push — master ( 6bac61...6350a6 )
by Kirill
03:02
created

DependentNameProvider::getFullName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 13
rs 9.8333
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\Support;
11
12
use Railt\Parser\Ast\LeafInterface;
13
use Railt\Parser\Ast\RuleInterface;
14
15
/**
16
 * Trait DependentNameProvider
17
 */
18
trait DependentNameProvider
19
{
20
    /**
21
     * @return null|string
22
     */
23
    public function getFullName(): ?string
24
    {
25
        $name = $this->getNameNode();
26
27
        if ($name instanceof RuleInterface) {
28
            /** @var LeafInterface $value */
29
            $value = $name->getChild(0);
30
31
            return $value->getValue();
32
        }
33
34
        return null;
35
    }
36
37
    /**
38
     * @return null|RuleInterface
39
     */
40
    protected function getNameNode(): ?RuleInterface
41
    {
42
        return $this->first('DependentName', 1);
0 ignored issues
show
Bug introduced by
It seems like first() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
43
    }
44
}
45