InfoWindowCollector   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 5
dl 0
loc 92
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMarkerCollector() 0 4 1
A setMarkerCollector() 0 4 1
A getType() 0 4 1
A setType() 0 4 1
B collect() 0 20 6
A collectValue() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Helper\Collector\Overlay;
13
14
use Ivory\GoogleMap\Helper\Collector\AbstractCollector;
15
use Ivory\GoogleMap\Map;
16
use Ivory\GoogleMap\Overlay\InfoWindow;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class InfoWindowCollector extends AbstractCollector
22
{
23
    const STRATEGY_MAP = 1;
24
    const STRATEGY_MARKER = 2;
25
26
    /**
27
     * @var MarkerCollector
28
     */
29
    private $markerCollector;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $type;
35
36
    /**
37
     * @param string|null $type
38
     */
39 144
    public function __construct(MarkerCollector $markerCollector, $type = null)
40
    {
41 144
        $this->setMarkerCollector($markerCollector);
42 144
        $this->setType($type);
43 144
    }
44
45
    /**
46
     * @return MarkerCollector
47
     */
48 4
    public function getMarkerCollector()
49
    {
50 4
        return $this->markerCollector;
51
    }
52
53 144
    public function setMarkerCollector(MarkerCollector $markerCollector)
54
    {
55 144
        $this->markerCollector = $markerCollector;
56 144
    }
57
58
    /**
59
     * @return string|null
60
     */
61 12
    public function getType()
62
    {
63 12
        return $this->type;
64
    }
65
66
    /**
67
     * @param string|null $type
68
     */
69 144
    public function setType($type)
70
    {
71 144
        $this->type = $type;
72 144
    }
73
74
    /**
75
     * @param InfoWindow[] $infoWindows
76
     * @param int|null     $strategy
77
     *
78
     * @return InfoWindow[]
79
     */
80 84
    public function collect(Map $map, array $infoWindows = [], $strategy = null)
81
    {
82 84
        if (null === $strategy) {
83 48
            $strategy = self::STRATEGY_MAP | self::STRATEGY_MARKER;
84
        }
85
86 84
        if ($strategy & self::STRATEGY_MAP) {
87 72
            $infoWindows = $this->collectValues($map->getOverlayManager()->getInfoWindows(), $infoWindows);
88
        }
89
90 84
        if ($strategy & self::STRATEGY_MARKER) {
91 72
            foreach ($this->markerCollector->collect($map) as $marker) {
92 32
                if ($marker->hasInfoWindow()) {
93 28
                    $infoWindows = $this->collectValue($marker->getInfoWindow(), $infoWindows);
94
                }
95
            }
96
        }
97
98 84
        return $infoWindows;
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104 44
    protected function collectValue($value, array $defaults = [])
105
    {
106 44
        if (null !== $this->type && $value->getType() !== $this->type) {
107 24
            return $defaults;
108
        }
109
110 44
        return parent::collectValue($value, $defaults);
111
    }
112
}
113