NodeList::getBody()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * This file is part of Platform 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 Karma\Platform\Ast;
11
12
/**
13
 * Class NodeList
14
 * @package Karma\Platform\Ast
15
 */
16
final class NodeList implements \IteratorAggregate
17
{
18
    /**
19
     * @var array|NodeInterface[]
20
     */
21
    private $nodes = [];
22
23
    /**
24
     * NodeList constructor.
25
     * @param iterable|null $nodes
26
     */
27
    public function __construct(iterable $nodes = null)
28
    {
29
        if ($nodes !== null) {
30
            foreach ($nodes as $node) {
31
                $this->add($node);
32
            }
33
        }
34
    }
35
36
    /**
37
     * @param NodeInterface $node
38
     */
39
    public function add(NodeInterface $node)
40
    {
41
        $this->nodes[] = $node;
42
    }
43
44
    /**
45
     * @return \Traversable
46
     */
47
    public function getIterator(): \Traversable
48
    {
49
        return new \ArrayIterator($this->nodes);
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function __toString(): string
56
    {
57
        return $this->getBody();
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getBody(): string
64
    {
65
        $result = '';
66
67
        foreach ($this->nodes as $node) {
68
            $result .= $node->getBody();
69
        }
70
71
        return $result;
72
    }
73
}
74