Completed
Push — master ( 22fff6...9c0de7 )
by Kirill
03:23
created

DirectivesProvider::getDirectives()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 10
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 9.9332
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\Compiler\Ast\Common;
11
12
use Railt\SDL\Compiler\Ast\Dependent\DirectiveNode;
13
14
/**
15
 * Trait DirectivesProvider
16
 */
17
trait DirectivesProvider
18
{
19
    /**
20
     * @return iterable|DirectiveNode[]
21
     */
22 1
    public function getDirectives(): iterable
23
    {
24 1
        $directives = $this->first('Directives', 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...
25
26 1
        if ($directives) {
27
            foreach ($directives as $directive) {
28
                yield $directive;
29
            }
30
        }
31 1
    }
32
}
33