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

BoundSubscriber::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
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\BoundCollector;
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\BoundRenderer;
21
use Ivory\GoogleMap\Helper\Subscriber\AbstractSubscriber;
22
23
class BoundSubscriber extends AbstractSubscriber
24
{
25
    /** @var BoundCollector */
26
    private $boundCollector;
27
28
    /** @var BoundRenderer */
29
    private $boundRenderer;
30
31 1
    public function __construct(
32
        Formatter $formatter,
33
        BoundCollector $boundCollector,
34
        BoundRenderer $boundRenderer
35
    ) {
36 1
        parent::__construct($formatter);
37
38 1
        $this->setBoundCollector($boundCollector);
39 1
        $this->setBoundRenderer($boundRenderer);
40 1
    }
41
42
    public function getBoundCollector(): BoundCollector
43
    {
44
        return $this->boundCollector;
45
    }
46
47 1
    public function setBoundCollector(BoundCollector $boundCollector): void
48
    {
49 1
        $this->boundCollector = $boundCollector;
50 1
    }
51
52
    public function getBoundRenderer(): BoundRenderer
53
    {
54
        return $this->boundRenderer;
55
    }
56
57 1
    public function setBoundRenderer(BoundRenderer $boundRenderer): void
58
    {
59 1
        $this->boundRenderer = $boundRenderer;
60 1
    }
61
62
    public function handleMap(MapEvent $event): void
63
    {
64
        $formatter = $this->getFormatter();
65
        $map       = $event->getMap();
66
67
        foreach ($this->boundCollector->collect($map) as $bound) {
68
            $event->addCode($formatter->renderContainerAssignment(
69
                $map,
70
                $this->boundRenderer->render($bound),
71
                'base.bounds',
72
                $bound
73
            ));
74
        }
75
    }
76
77
    /** {@inheritdoc} */
78 1
    public static function getSubscribedEvents(): array
79
    {
80 1
        return [MapEvents::JAVASCRIPT_BASE_BOUND => 'handleMap'];
81
    }
82
}
83