GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f79bcb...de7e43 )
by Eric
80:29 queued 77:22
created

setInfoWindowOpenRenderer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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\Subscriber\Overlay;
13
14
use Ivory\GoogleMap\Event\Event;
15
use Ivory\GoogleMap\Helper\Collector\Overlay\MarkerCollector;
16
use Ivory\GoogleMap\Helper\Event\MapEvent;
17
use Ivory\GoogleMap\Helper\Event\MapEvents;
18
use Ivory\GoogleMap\Helper\Formatter\Formatter;
19
use Ivory\GoogleMap\Helper\Renderer\Event\EventRenderer;
20
use Ivory\GoogleMap\Helper\Renderer\Overlay\InfoWindowOpenRenderer;
21
use Ivory\GoogleMap\Map;
22
use Ivory\GoogleMap\Overlay\Marker;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27
class MarkerInfoWindowOpenSubscriber extends AbstractMarkerSubscriber
28
{
29
    /**
30
     * @var InfoWindowOpenRenderer
31
     */
32
    private $infoWindowOpenRenderer;
33
34
    /**
35
     * @var EventRenderer
36
     */
37
    private $eventRenderer;
38
39
    /**
40
     * @param Formatter              $formatter
41
     * @param MarkerCollector        $markerCollector
42
     * @param InfoWindowOpenRenderer $infoWindowOpenRenderer
43
     * @param EventRenderer          $eventRenderer
44
     */
45 224
    public function __construct(
46
        Formatter $formatter,
47
        MarkerCollector $markerCollector,
48
        InfoWindowOpenRenderer $infoWindowOpenRenderer,
49
        EventRenderer $eventRenderer
50
    ) {
51 224
        parent::__construct($formatter, $markerCollector);
52
53 224
        $this->setInfoWindowOpenRenderer($infoWindowOpenRenderer);
54 224
        $this->setEventRenderer($eventRenderer);
55 224
    }
56
57
    /**
58
     * @return InfoWindowOpenRenderer
59
     */
60 16
    public function getInfoWindowOpenRenderer()
61
    {
62 16
        return $this->infoWindowOpenRenderer;
63
    }
64
65
    /**
66
     * @param InfoWindowOpenRenderer $infoWindowOpenRenderer
67
     */
68 224
    public function setInfoWindowOpenRenderer(InfoWindowOpenRenderer $infoWindowOpenRenderer)
69
    {
70 224
        $this->infoWindowOpenRenderer = $infoWindowOpenRenderer;
71 224
    }
72
73
    /**
74
     * @return EventRenderer
75
     */
76 16
    public function getEventRenderer()
77
    {
78 16
        return $this->eventRenderer;
79
    }
80
81
    /**
82
     * @param EventRenderer $eventRenderer
83
     */
84 224
    public function setEventRenderer(EventRenderer $eventRenderer)
85
    {
86 224
        $this->eventRenderer = $eventRenderer;
87 224
    }
88
89
    /**
90
     * @param MapEvent $event
91
     */
92 220
    public function handleMap(MapEvent $event)
93
    {
94 220
        $formatter = $this->getFormatter();
95 220
        $map = $event->getMap();
96
97 220
        foreach ($this->getMarkerCollector()->collect($map) as $marker) {
98 48
            if ($marker->hasInfoWindow() && $marker->getInfoWindow()->isAutoOpen()) {
99 16
                $event->addCode($formatter->renderContainerAssignment(
100 8
                    $map,
101 16
                    $this->getEventRenderer()->render($rawEvent = $this->createEvent($map, $marker)),
102 32
                    'events.events',
103
                    $rawEvent
104 8
                ));
105 8
            }
106 110
        }
107 220
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112 224
    public static function getSubscribedEvents()
113
    {
114 224
        return [MapEvents::JAVASCRIPT_EVENT => 'handleMap'];
115
    }
116
117
    /**
118
     * @param Map    $map
119
     * @param Marker $marker
120
     *
121
     * @return Event
122
     */
123 16
    private function createEvent(Map $map, Marker $marker)
124
    {
125 16
        $formatter = $this->getFormatter();
126
127 16
        $rawEvent = new Event(
128 16
            $marker->getVariable(),
129 16
            $marker->getInfoWindow()->getOpenEvent(),
130 16
            $formatter->renderClosure($formatter->renderLines([
131 16
                $formatter->renderCall(
132 16
                    $formatter->renderProperty(
133 16
                        $formatter->renderContainerVariable($map, 'functions'),
134 8
                        'info_windows_close'
135 8
                    ),
136 16
                    [],
137 8
                    true
138 8
                ),
139 16
                $formatter->renderCode(
140 16
                    $this->getInfoWindowOpenRenderer()->render($marker->getInfoWindow(), $map, $marker),
0 ignored issues
show
Bug introduced by
It seems like $marker->getInfoWindow() can be null; however, render() 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...
141 16
                    true,
142 8
                    false
143 8
                ),
144 8
            ]))
145 8
        );
146
147 16
        $rawEvent->setVariable($marker->getVariable().'_info_window_open_event');
148
149 16
        return $rawEvent;
150
    }
151
}
152