Completed
Push — master ( 332a4c...198c54 )
by Kirill
02:13
created

InputValueNode::getValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 7
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\Value;
11
12
use Railt\Parser\Ast\Rule;
13
use Railt\Parser\Ast\RuleInterface;
14
15
/**
16
 * Class InputValueNode
17
 */
18
class InputValueNode extends Rule implements ValueInterface, CompositeValueInterface
19
{
20
    /**
21
     * @return iterable
22
     */
23
    public function toPrimitive(): iterable
24
    {
25
        foreach ($this->getValues() as $key => $value) {
26
            yield $key => $value->toPrimitive();
27
        }
28
    }
29
30
    /**
31
     * @return iterable|ValueInterface[]
32
     */
33
    public function getValues(): iterable
34
    {
35
        /** @var RuleInterface $child */
36
        foreach ($this->getChildren() as $child) {
37
            yield $this->key($child) => $this->value($child);
38
        }
39
    }
40
41
    /**
42
     * @param RuleInterface $rule
43
     * @return ValueInterface|RuleInterface
44
     */
45
    private function value(RuleInterface $rule): ValueInterface
46
    {
47
        /** @var RuleInterface $value */
48
        $value = $rule->first('Value', 1);
49
50
        return $value->getChild(0);
51
    }
52
53
    /**
54
     * @param RuleInterface $rule
55
     * @return string
56
     */
57
    private function key(RuleInterface $rule): string
58
    {
59
        /** @var RuleInterface $key */
60
        $key = $rule->first('Key', 1);
61
62
        return $key->getChild(0)->getValue();
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on Railt\Parser\Ast\NodeInterface. Did you maybe mean getValues()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
63
    }
64
}
65