NodeList   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 58
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A add() 0 4 1
A getIterator() 0 4 1
A __toString() 0 4 1
A getBody() 0 10 2
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