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\Renderer\Control; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Control\FullscreenControl; |
15
|
|
|
use Ivory\GoogleMap\Helper\Formatter\Formatter; |
16
|
|
|
use Ivory\GoogleMap\Helper\Renderer\AbstractJsonRenderer; |
17
|
|
|
use Ivory\JsonBuilder\JsonBuilder; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class FullscreenControlRenderer extends AbstractJsonRenderer implements ControlRendererInterface |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ControlPositionRenderer |
26
|
|
|
*/ |
27
|
|
|
private $controlPositionRenderer; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Formatter $formatter |
31
|
|
|
* @param JsonBuilder $jsonBuilder |
32
|
|
|
* @param ControlPositionRenderer $controlPositionRenderer |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
Formatter $formatter, |
36
|
|
|
JsonBuilder $jsonBuilder, |
37
|
|
|
ControlPositionRenderer $controlPositionRenderer |
38
|
|
|
) { |
39
|
|
|
parent::__construct($formatter, $jsonBuilder); |
40
|
|
|
|
41
|
|
|
$this->setControlPositionRenderer($controlPositionRenderer); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return ControlPositionRenderer |
46
|
|
|
*/ |
47
|
|
|
public function getControlPositionRenderer() |
48
|
|
|
{ |
49
|
|
|
return $this->controlPositionRenderer; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param ControlPositionRenderer $controlPositionRenderer |
54
|
|
|
*/ |
55
|
|
|
public function setControlPositionRenderer(ControlPositionRenderer $controlPositionRenderer) |
56
|
|
|
{ |
57
|
|
|
$this->controlPositionRenderer = $controlPositionRenderer; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function render($control) |
64
|
|
|
{ |
65
|
|
|
if (!$control instanceof FullscreenControl) { |
66
|
|
|
throw new \InvalidArgumentException(sprintf( |
67
|
|
|
'Expected a "%s", got "%s".', |
68
|
|
|
FullscreenControl::class, |
69
|
|
|
is_object($control) ? get_class($control) : gettype($control) |
70
|
|
|
)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->getJsonBuilder() |
74
|
|
|
->setValue('[position]', $this->controlPositionRenderer->render($control->getPosition()), false) |
75
|
|
|
->build(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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.