SizeCollector   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 70
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getInfoWindowCollector() 0 4 1
A setInfoWindowCollector() 0 4 1
A getIconCollector() 0 4 1
A setIconCollector() 0 4 1
B collect() 0 20 6
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\Base;
13
14
use Ivory\GoogleMap\Base\Size;
15
use Ivory\GoogleMap\Helper\Collector\AbstractCollector;
16
use Ivory\GoogleMap\Helper\Collector\Overlay\IconCollector;
17
use Ivory\GoogleMap\Helper\Collector\Overlay\InfoWindowCollector;
18
use Ivory\GoogleMap\Map;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class SizeCollector extends AbstractCollector
24
{
25
    /**
26
     * @var InfoWindowCollector
27
     */
28
    private $infoWindowCollector;
29
30
    /**
31
     * @var IconCollector
32
     */
33
    private $iconCollector;
34
35 24
    public function __construct(InfoWindowCollector $infoWindowCollector, IconCollector $iconCollector)
36
    {
37 24
        $this->setInfoWindowCollector($infoWindowCollector);
38 24
        $this->setIconCollector($iconCollector);
39 24
    }
40
41
    /**
42
     * @return InfoWindowCollector
43
     */
44 4
    public function getInfoWindowCollector()
45
    {
46 4
        return $this->infoWindowCollector;
47
    }
48
49 24
    public function setInfoWindowCollector(InfoWindowCollector $infoWindowCollector)
50
    {
51 24
        $this->infoWindowCollector = $infoWindowCollector;
52 24
    }
53
54
    /**
55
     * @return IconCollector
56
     */
57 4
    public function getIconCollector()
58
    {
59 4
        return $this->iconCollector;
60
    }
61
62 24
    public function setIconCollector(IconCollector $iconCollector)
63
    {
64 24
        $this->iconCollector = $iconCollector;
65 24
    }
66
67
    /**
68
     * @param Size[] $sizes
69
     *
70
     * @return Size[]
71
     */
72 12
    public function collect(Map $map, array $sizes = [])
73
    {
74 12
        foreach ($this->infoWindowCollector->collect($map) as $infoWindow) {
75 4
            if ($infoWindow->hasPixelOffset()) {
76 4
                $sizes = $this->collectValue($infoWindow->getPixelOffset(), $sizes);
0 ignored issues
show
Bug introduced by
It seems like $infoWindow->getPixelOffset() can be null; however, collectValue() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
77
            }
78
        }
79
80 12
        foreach ($this->iconCollector->collect($map) as $icon) {
81 4
            if ($icon->hasSize()) {
82 4
                $sizes = $this->collectValue($icon->getSize(), $sizes);
83
            }
84
85 4
            if ($icon->hasScaledSize()) {
86 4
                $sizes = $this->collectValue($icon->getScaledSize(), $sizes);
87
            }
88
        }
89
90 12
        return $sizes;
91
    }
92
}
93