Completed
Push — master ( 7510c8...82c7bd )
by Kirill
08:19
created

DirectiveDefinitionNode::getLocations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 6
rs 9.9666
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\Definition;
11
12
use Railt\Parser\Ast\LeafInterface;
13
use Railt\SDL\Compiler\Ast\Dependent\ArgumentDefinitionNode;
14
15
/**
16
 * Class DirectiveDefinitionNode
17
 */
18
class DirectiveDefinitionNode extends TypeDefinitionNode
19
{
20
    /**
21
     * @return iterable|string[]
22
     */
23
    public function getLocations(): iterable
24
    {
25
        $locations = $this->first('DirectiveLocations', 1);
26
27
        /** @var LeafInterface $location */
28
        foreach ($locations as $location) {
0 ignored issues
show
Bug introduced by
The expression $locations of type null|object<Railt\Parser\Ast\NodeInterface> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
29
            yield $location->getValue();
30
        }
31
    }
32
33
    /**
34
     * @return iterable|ArgumentDefinitionNode[]
35
     */
36
    public function getArguments(): iterable
37
    {
38
        $arguments = $this->first('DirectiveArguments', 1);
39
40
        if ($arguments) {
41
            foreach ($arguments as $argument) {
0 ignored issues
show
Bug introduced by
The expression $arguments of type object<Railt\Parser\Ast\NodeInterface> is not traversable.
Loading history...
42
                yield $argument;
43
            }
44
        }
45
    }
46
}
47