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

SchemaDefinitionNode::getSchemaFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

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 8
ccs 0
cts 7
cp 0
crap 6
rs 10
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\SDL\Compiler\Ast\Dependent\SchemaFieldDefinitionNode;
13
14
/**
15
 * Class SchemaDefinitionNode
16
 */
17
class SchemaDefinitionNode extends TypeDefinitionNode
18
{
19
    /**
20
     * @return iterable|SchemaFieldDefinitionNode[]
21
     */
22
    public function getSchemaFields(): iterable
23
    {
24
        $fields = $this->first('SchemaFields', 1);
25
26
        foreach ($fields as $field) {
0 ignored issues
show
Bug introduced by
The expression $fields 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...
27
            yield $field;
28
        }
29
    }
30
}
31