Completed
Push — master ( 8afd90...4bf010 )
by Kirill
03:48
created

ListValueNode::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
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
14
/**
15
 * Class ListValueNode
16
 */
17
class ListValueNode extends Rule implements ValueInterface
18
{
19
    /**
20
     * @return string
21
     */
22
    public function toString(): string
23
    {
24
        $values = \array_map(function (ValueInterface $value) {
25
            return $value->toString();
26
        }, \iterator_to_array($this->getValues()));
27
28
        return \sprintf('[%s]', \implode(', ', $values));
29
    }
30
31
    /**
32
     * @return iterable|ValueInterface[]
33
     */
34
    public function toPrimitive(): iterable
35
    {
36
        return \array_map(function (ValueInterface $value) {
37
            return $value->toPrimitive();
38
        }, \iterator_to_array($this->getValues()));
39
    }
40
41
    /**
42
     * @return iterable|ValueInterface[]
43
     */
44
    public function getValues(): iterable
45
    {
46
        foreach ($this->getChildren() as $children) {
47
            yield $children->getInnerValue();
48
        }
49
    }
50
}
51