TypeCollection::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Arthem\GoogleApi\Domain\Place\VO;
4
5
use Arthem\GoogleApi\Domain\Place\Exception\InvalidTypeException;
6
7
class TypeCollection implements \IteratorAggregate
8
{
9
    /**
10
     * @var Type[]
11
     */
12
    private $types;
13
14
    /**
15
     * @param Type[] $types
16
     */
17
    public function __construct(array $types = [])
18
    {
19
        foreach ($types as $type) {
20
            if (!$type instanceof Type) {
21
                throw new InvalidTypeException(sprintf('Expected instance of %s, got %s', Type::class, gettype($type)));
22
            }
23
        }
24
25
        $this->types = $types;
26
    }
27
28
    /**
29
     * @param Type $type
30
     *
31
     * @return $this
32
     */
33
    public function addType(Type $type)
34
    {
35
        $this->types[] = $type;
36
37
        return $this;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getIterator()
44
    {
45
        return new \ArrayIterator($this->types);
46
    }
47
}
48