Completed
Push — master ( 93bbfd...32f969 )
by Arthur
02:17
created

AddressComponentCollection::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Arthem\GoogleApi\Domain\Place\VO;
4
5
class AddressComponentCollection implements \IteratorAggregate
6
{
7
    /**
8
     * @var AddressComponent[]
9
     */
10
    private $components = [];
11
12
    /**
13
     * @param AddressComponent $component
14
     *
15
     * @return $this
16
     */
17
    public function addComponent(AddressComponent $component)
18
    {
19
        $this->components[] = $component;
20
21
        return $this;
22
    }
23
24
    /**
25
     * @param string $type
26
     *
27
     * @return AddressComponent|null
28
     */
29
    public function findOneComponentByType($type)
30
    {
31
        foreach ($this->components as $component) {
32
            if ($component->hasType($type)) {
33
                return $component;
34
            }
35
        }
36
    }
37
38
    /**
39
     * @param string $type
40
     *
41
     * @return array
42
     */
43
    public function findComponentsByType($type)
44
    {
45
        $components = [];
46
        foreach ($this->components as $component) {
47
            if ($component->hasType($type)) {
48
                $components[] = $component;
49
            }
50
        }
51
52
        return $components;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getIterator()
59
    {
60
        return new \ArrayIterator($this->components);
61
    }
62
}
63