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

InfoBoxSubscriber::setInfoBoxRenderer()   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\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 272
    public function __construct(
41
        Formatter $formatter,
42
        InfoBoxCollector $infoBoxCollector,
43
        InfoBoxRenderer $infoBoxRenderer
44
    ) {
45 272
        parent::__construct($formatter, $infoBoxCollector);
46
47 272
        $this->setInfoBoxRenderer($infoBoxRenderer);
48 272
    }
49
50
    /**
51
     * @return InfoBoxRenderer
52
     */
53 28
    public function getInfoBoxRenderer()
54
    {
55 28
        return $this->infoBoxRenderer;
56
    }
57
58
    /**
59
     * @param InfoBoxRenderer $infoBoxRenderer
60
     */
61 272
    public function setInfoBoxRenderer(InfoBoxRenderer $infoBoxRenderer)
62
    {
63 272
        $this->infoBoxRenderer = $infoBoxRenderer;
64 272
    }
65
66
    /**
67
     * @param ApiEvent $event
68
     */
69 264
    public function handleApi(ApiEvent $event)
70
    {
71 264
        foreach ($event->getObjects(Map::class) as $map) {
72 220
            $infoBoxes = $this->getInfoWindowCollector()->collect($map);
73
74 220
            if (!empty($infoBoxes)) {
75 28
                $event->addSource($this->getInfoBoxRenderer()->renderSource());
76 28
                $event->addRequirement($map, $this->getInfoBoxRenderer()->renderRequirement());
77
78 124
                continue;
79
            }
80 132
        }
81 264
    }
82
83
    /**
84
     * @param MapEvent $event
85
     */
86 220 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 220
        $map = $event->getMap();
89 220
        $collector = $this->getInfoWindowCollector();
90
91 220
        foreach ($collector->collect($map, [], InfoWindowCollector::STRATEGY_MAP) as $infoWindow) {
92 20
            $event->addCode($this->renderInfoBox($map, $infoWindow));
93 110
        }
94
95 220
        foreach ($collector->collect($map, [], InfoWindowCollector::STRATEGY_MARKER) as $infoWindow) {
96 8
            $event->addCode($this->renderInfoBox($map, $infoWindow, false));
97 110
        }
98 220
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 272
    public static function getSubscribedEvents()
104
    {
105
        return [
106 272
            ApiEvents::JAVASCRIPT_MAP                 => 'handleApi',
107 272
            MapEvents::JAVASCRIPT_OVERLAY_INFO_WINDOW => 'handleMap',
108 136
        ];
109
    }
110
111
    /**
112
     * @param Map        $map
113
     * @param InfoWindow $infoWindow
114
     * @param bool       $position
115
     *
116
     * @return string
117
     */
118 28
    private function renderInfoBox(Map $map, InfoWindow $infoWindow, $position = true)
119
    {
120 28
        return $this->getFormatter()->renderContainerAssignment(
121 14
            $map,
122 28
            $this->getInfoBoxRenderer()->render($infoWindow, $position),
123 28
            'overlays.info_boxes',
124
            $infoWindow
125 14
        );
126
    }
127
}
128