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 — heatmap-layer ( 9858f3 )
by Eric
02:46
created

HeatmapLayerSubscriber   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 105
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 11
c 1
b 0
f 1
lcom 1
cbo 6
dl 105
loc 105
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 1
A getHeatmapLayerCollector() 4 4 1
A setHeatmapLayerCollector() 4 4 1
A getHeatmapLayerRenderer() 4 4 1
A setHeatmapLayerRenderer() 4 4 1
A handleApi() 12 12 3
A handleMap() 14 14 2
A getSubscribedEvents() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Layer;
13
14
use Ivory\GoogleMap\Helper\Collector\Layer\HeatmapLayerCollector;
15
use Ivory\GoogleMap\Helper\Event\ApiEvent;
16
use Ivory\GoogleMap\Helper\Event\ApiEvents;
17
use Ivory\GoogleMap\Helper\Event\MapEvent;
18
use Ivory\GoogleMap\Helper\Event\MapEvents;
19
use Ivory\GoogleMap\Helper\Formatter\Formatter;
20
use Ivory\GoogleMap\Helper\Renderer\Layer\HeatmapLayerRenderer;
21
use Ivory\GoogleMap\Helper\Subscriber\AbstractSubscriber;
22
use Ivory\GoogleMap\Map;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27 View Code Duplication
class HeatmapLayerSubscriber extends AbstractSubscriber
0 ignored issues
show
Duplication introduced by
This class 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...
28
{
29
    /**
30
     * @var HeatmapLayerCollector
31
     */
32
    private $heatmapLayerCollector;
33
34
    /**
35
     * @var HeatmapLayerRenderer
36
     */
37
    private $heatmapLayerRenderer;
38
39
    /**
40
     * @param Formatter         $formatter
41
     * @param HeatmapLayerCollector $heatmapLayerCollector
42
     * @param HeatmapLayerRenderer  $heatmapLayerRenderer
43
     */
44
    public function __construct(
45
        Formatter $formatter,
46
        HeatmapLayerCollector $heatmapLayerCollector,
47
        HeatmapLayerRenderer $heatmapLayerRenderer
48
    ) {
49
        parent::__construct($formatter);
50
51
        $this->setHeatmapLayerCollector($heatmapLayerCollector);
52
        $this->setHeatmapLayerRenderer($heatmapLayerRenderer);
53
    }
54
55
    /**
56
     * @return HeatmapLayerCollector
57
     */
58
    public function getHeatmapLayerCollector()
59
    {
60
        return $this->heatmapLayerCollector;
61
    }
62
63
    /**
64
     * @param HeatmapLayerCollector $heatmapLayerCollector
65
     */
66
    public function setHeatmapLayerCollector(HeatmapLayerCollector $heatmapLayerCollector)
67
    {
68
        $this->heatmapLayerCollector = $heatmapLayerCollector;
69
    }
70
71
    /**
72
     * @return HeatmapLayerRenderer
73
     */
74
    public function getHeatmapLayerRenderer()
75
    {
76
        return $this->heatmapLayerRenderer;
77
    }
78
79
    /**
80
     * @param HeatmapLayerRenderer $heatmapLayerRenderer
81
     */
82
    public function setHeatmapLayerRenderer(HeatmapLayerRenderer $heatmapLayerRenderer)
83
    {
84
        $this->heatmapLayerRenderer = $heatmapLayerRenderer;
85
    }
86
87
    /**
88
     * @param ApiEvent $event
89
     */
90
    public function handleApi(ApiEvent $event)
91
    {
92
        foreach ($event->getObjects(Map::class) as $map) {
93
            $heatmapLayers = $this->heatmapLayerCollector->collect($map);
94
95
            if (!empty($heatmapLayers)) {
96
                $event->addLibrary('visualization');
97
98
                break;
99
            }
100
        }
101
    }
102
103
    /**
104
     * @param MapEvent $event
105
     */
106
    public function handleMap(MapEvent $event)
107
    {
108
        $formatter = $this->getFormatter();
109
        $map = $event->getMap();
110
111
        foreach ($this->heatmapLayerCollector->collect($map) as $heatmapLayer) {
112
            $event->addCode($formatter->renderContainerAssignment(
113
                $map,
114
                $this->heatmapLayerRenderer->render($heatmapLayer, $map),
115
                'layers.heatmap_layers',
116
                $heatmapLayer
117
            ));
118
        }
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public static function getSubscribedEvents()
125
    {
126
        return [
127
            ApiEvents::JAVASCRIPT_MAP                 => 'handleApi',
128
            MapEvents::JAVASCRIPT_LAYER_HEATMAP_LAYER => 'handleMap'
129
        ];
130
    }
131
}
132