Passed
Push — feature/v4 ( 69e935...62277d )
by Samuel
05:01
created

PointSubscriber   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 48.15%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 1
b 0
f 0
dl 0
loc 58
ccs 13
cts 27
cp 0.4815
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setPointRenderer() 0 3 1
A __construct() 0 9 1
A getPointRenderer() 0 3 1
A getSubscribedEvents() 0 3 1
A setPointCollector() 0 3 1
A getPointCollector() 0 3 1
A handleMap() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Ivory Google Map package.
7
 *
8
 * (c) Eric GELOEN <[email protected]>
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ivory\GoogleMap\Helper\Subscriber\Base;
15
16
use Ivory\GoogleMap\Helper\Collector\Base\PointCollector;
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\Base\PointRenderer;
21
use Ivory\GoogleMap\Helper\Subscriber\AbstractSubscriber;
22
23
class PointSubscriber extends AbstractSubscriber
24
{
25
    /** @var PointCollector */
26
    private $pointCollector;
27
28
    /** @var PointRenderer */
29
    private $pointRenderer;
30
31 1
    public function __construct(
32
        Formatter $formatter,
33
        PointCollector $pointCollector,
34
        PointRenderer $pointRenderer
35
    ) {
36 1
        parent::__construct($formatter);
37
38 1
        $this->setPointCollector($pointCollector);
39 1
        $this->setPointRenderer($pointRenderer);
40 1
    }
41
42
    public function getPointCollector(): PointCollector
43
    {
44
        return $this->pointCollector;
45
    }
46
47 1
    public function setPointCollector(PointCollector $pointCollector): void
48
    {
49 1
        $this->pointCollector = $pointCollector;
50 1
    }
51
52
    public function getPointRenderer(): PointRenderer
53
    {
54
        return $this->pointRenderer;
55
    }
56
57 1
    public function setPointRenderer(PointRenderer $pointRenderer): void
58
    {
59 1
        $this->pointRenderer = $pointRenderer;
60 1
    }
61
62
    public function handleMap(MapEvent $event): void
63
    {
64
        $formatter = $this->getFormatter();
65
        $map       = $event->getMap();
66
67
        foreach ($this->pointCollector->collect($map) as $point) {
68
            $event->addCode($formatter->renderContainerAssignment(
69
                $map,
70
                $this->pointRenderer->render($point),
71
                'base.points',
72
                $point
73
            ));
74
        }
75
    }
76
77
    /** {@inheritdoc} */
78 1
    public static function getSubscribedEvents(): array
79
    {
80 1
        return [MapEvents::JAVASCRIPT_BASE_POINT => 'handleMap'];
81
    }
82
}
83