Completed
Push — master ( db026b...56b106 )
by Oliver
04:09 queued 02:28
created

NamedCollection::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Metabor;
4
5
use MetaborStd\NamedCollectionInterface;
6
use MetaborStd\NamedInterface;
7
8
/**
9
 * @author Oliver Tischlinger
10
 */
11
class NamedCollection implements \IteratorAggregate, NamedCollectionInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $collection = array();
17
18
    /**
19
     * @see MetaborStd.NamedCollectionInterface::add()
20
     */
21 29
    public function add(NamedInterface $object)
22
    {
23 29
        $this->collection[$object->getName()] = $object;
24 29
    }
25
26
    /**
27
     * @see MetaborStd.NamedCollectionInterface::get()
28
     */
29 12
    public function get($name)
30
    {
31 12
        return $this->collection[$name];
32
    }
33
34
    /**
35
     * @see MetaborStd.NamedCollectionInterface::getNames()
36
     */
37 6
    public function getNames()
38
    {
39 6
        return array_keys($this->collection);
40
    }
41
42
    /**
43
     * @see MetaborStd.NamedCollectionInterface::has()
44
     */
45 22
    public function has($name)
46
    {
47 22
        return isset($this->collection[$name]);
48
    }
49
50
    /**
51
     * @see \IteratorAggregate::getIterator()
52
     */
53 12
    public function getIterator()
54
    {
55 12
        return new \ArrayIterator($this->collection);
56
    }
57
}
58