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 ( 898d2c...c462d0 )
by Eric
24:16 queued 21:28
created

InfoBoxSubscriber::handleMap()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 1
crap 12
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\Helper\Collector\Overlay\InfoBoxCollector;
15
use Ivory\GoogleMap\Helper\Collector\Overlay\InfoWindowCollector;
16
use Ivory\GoogleMap\Helper\Event\ApiEvent;
17
use Ivory\GoogleMap\Helper\Event\ApiEvents;
18
use Ivory\GoogleMap\Helper\Event\MapEvent;
19
use Ivory\GoogleMap\Helper\Event\MapEvents;
20
use Ivory\GoogleMap\Helper\Formatter\Formatter;
21
use Ivory\GoogleMap\Helper\Renderer\Overlay\InfoBoxRenderer;
22
use Ivory\GoogleMap\Map;
23
use Ivory\GoogleMap\Overlay\InfoWindow;
24
25
/**
26
 * @author GeLo <[email protected]>
27
 */
28
class InfoBoxSubscriber extends AbstractInfoWindowSubscriber
29
{
30
    /**
31
     * @var InfoBoxRenderer
32
     */
33
    private $infoBoxRenderer;
34
35
    /**
36
     * @param Formatter        $formatter
37
     * @param InfoBoxCollector $infoBoxCollector
38
     * @param InfoBoxRenderer  $infoBoxRenderer
39
     */
40 8
    public function __construct(
41
        Formatter $formatter,
42
        InfoBoxCollector $infoBoxCollector,
43
        InfoBoxRenderer $infoBoxRenderer
44
    ) {
45 8
        parent::__construct($formatter, $infoBoxCollector);
46
47 8
        $this->setInfoBoxRenderer($infoBoxRenderer);
48 8
    }
49
50
    /**
51
     * @return InfoBoxRenderer
52
     */
53
    public function getInfoBoxRenderer()
54
    {
55
        return $this->infoBoxRenderer;
56
    }
57
58
    /**
59
     * @param InfoBoxRenderer $infoBoxRenderer
60
     */
61 8
    public function setInfoBoxRenderer(InfoBoxRenderer $infoBoxRenderer)
62
    {
63 8
        $this->infoBoxRenderer = $infoBoxRenderer;
64 8
    }
65
66
    /**
67
     * @param ApiEvent $event
68
     */
69
    public function handleApi(ApiEvent $event)
70
    {
71
        foreach ($event->getObjects(Map::class) as $map) {
72
            $infoBoxes = $this->getInfoWindowCollector()->collect($map);
73
74
            if (!empty($infoBoxes)) {
75
                $event->addSource($this->getInfoBoxRenderer()->renderSource());
76
                $event->addRequirement($map, $this->getInfoBoxRenderer()->renderRequirement());
77
78
                continue;
79
            }
80
        }
81
    }
82
83
    /**
84
     * @param MapEvent $event
85
     */
86 View Code Duplication
    public function handleMap(MapEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $map = $event->getMap();
89
        $collector = $this->getInfoWindowCollector();
90
91
        foreach ($collector->collect($map, [], InfoWindowCollector::STRATEGY_MAP) as $infoWindow) {
92
            $event->addCode($this->renderInfoBox($map, $infoWindow));
93
        }
94
95
        foreach ($collector->collect($map, [], InfoWindowCollector::STRATEGY_MARKER) as $infoWindow) {
96
            $event->addCode($this->renderInfoBox($map, $infoWindow, false));
97
        }
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 8
    public static function getSubscribedEvents()
104
    {
105
        return [
106 8
            ApiEvents::JAVASCRIPT_MAP                 => 'handleApi',
107 8
            MapEvents::JAVASCRIPT_OVERLAY_INFO_WINDOW => 'handleMap',
108 4
        ];
109
    }
110
111
    /**
112
     * @param Map        $map
113
     * @param InfoWindow $infoWindow
114
     * @param bool       $position
115
     *
116
     * @return string
117
     */
118
    private function renderInfoBox(Map $map, InfoWindow $infoWindow, $position = true)
119
    {
120
        return $this->getFormatter()->renderContainerAssignment(
121
            $map,
122
            $this->getInfoBoxRenderer()->render($infoWindow, $position),
123
            'overlays.info_boxes',
124
            $infoWindow
125
        );
126
    }
127
}
128