NodeList   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 4
A getIterator() 0 3 1
A add() 0 3 1
1
<?php
2
3
namespace OpenMindParser\Models;
4
5
use \InvalidArgumentException;
6
use \ArrayIterator;
7
8
/*A class to store a collection of Node Objects as a Traversable entity.*/
9
class NodeList implements \IteratorAggregate
10
{
11
	/**
12
	 * @var Node[]
13
	 */
14
	private $list;
15
	
16
	public function __construct(array $list = null) {
17
		if(empty($list)) {
18
			$list = [];
19
		}
20
		
21
		foreach($list as $node) {
22
			if(!($node instanceof Node)) {
23
				throw new InvalidArgumentException('The array must contain only Node objects. "'.get_class($node).'" given.');
24
			}
25
		}
26
		
27
		$this->list = $list;
28
	}
29
	
30
	/**
31
	 * Method to retrieve the iterrator on the list property.
32
	 * 
33
	 * @return ArrayIterator : the ArrayInterrator instance with the current collection.
34
	 */
35
	public function getIterator() {
36
		return new ArrayIterator($this->list);
37
	}
38
	
39
	/**
40
	 * Add a Node object to the collection.
41
	 * 
42
	 * @param Node $node : The Node instance to add to the current collection.
43
	 */
44
	public function add(Node $node) {
45
		$this->list[] = $node;
46
	}
47
}