Completed
Push — leaflet ( 284e1e...b8e3f3 )
by Jeroen De
05:53 queued 03:36
created

MapsLeaflet::getDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Class holding information and functionality specific to Leaflet.
5
 * This information and features can be used by any mapping feature.
6
 *
7
 * @licence GNU GPL v2+
8
 * @author Pavel Astakhov < [email protected] >
9
 */
10
class MapsLeaflet extends MapsMappingService {
11
12
	/**
13
	 * Constructor
14
	 */
15
	public function __construct( $serviceName ) {
16
		parent::__construct(
17
			$serviceName,
18
			[ 'leafletmaps', 'leaflet' ]
19
		);
20
	}
21
22
	/**
23
	 * @see MapsMappingService::addParameterInfo
24
	 *
25
	 * @since 3.0
26
	 */
27
	public function addParameterInfo( array &$params ) {
0 ignored issues
show
Coding Style introduced by
addParameterInfo uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
28
		global $GLOBALS;
29
30
		$params['zoom'] = [
31
			'type' => 'integer',
32
			'range' => [ 0, 20 ],
33
			'default' => false,
34
			'message' => 'maps-par-zoom'
35
		];
36
37
		$params['defzoom'] = [
38
			'type' => 'integer',
39
			'range' => [ 0, 20 ],
40
			'default' => self::getDefaultZoom(),
41
			'message' => 'maps-leaflet-par-defzoom'
42
		];
43
44
		$params['layer'] = [
45
			'type' => 'string',
46
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableLayers'], true, true ),
47
			'default' => $GLOBALS['egMapsLeafletLayer'],
48
			'message' =>'maps-leaflet-par-layer',
49
		];
50
51
		$params['overlaylayers'] = [
52
			'type' => 'string',
53
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableOverlayLayers'], true, true ),
54
			'default' => $GLOBALS['egMapsLeafletOverlayLayers'],
55
			'message' =>'maps-leaflet-par-overlaylayers',
56
			'islist' => true,
57
		];
58
59
		$params['resizable'] = [
60
			'type' => 'boolean',
61
			'default' => $GLOBALS['egMapsResizableByDefault'],
62
			'message' => 'maps-par-resizable'
63
		];
64
65
		$params['enablefullscreen'] = [
66
			'type' => 'boolean',
67
			'default' => false,
68
			'message' => 'maps-par-enable-fullscreen',
69
		];
70
71
		$params['markercluster'] = [
72
			'type' => 'boolean',
73
			'default' => false,
74
			'message' => 'maps-par-markercluster',
75
		];
76
77
		$params['clustermaxzoom'] = [
78
			'type' => 'integer',
79
			'default' => 20,
80
			'message' => 'maps-par-clustermaxzoom',
81
		];
82
83
		$params['clusterzoomonclick'] = [
84
			'type' => 'boolean',
85
			'default' => true,
86
			'message' => 'maps-par-clusterzoomonclick',
87
		];
88
89
		$params['clustermaxradius'] = [
90
			'type' => 'integer',
91
			'default' => 80,
92
			'message' => 'maps-par-maxclusterradius',
93
		];
94
95
		$params['clusterspiderfy'] = [
96
			'type' => 'boolean',
97
			'default' => true,
98
			'message' => 'maps-leaflet-par-clusterspiderfy',
99
		];
100
	}
101
102
	/**
103
	 * @since 3.0
104
	 */
105
	public function getDefaultZoom() {
0 ignored issues
show
Coding Style introduced by
getDefaultZoom uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
106
		return $GLOBALS['egMapsLeafletZoom'];
107
	}
108
109
	/**
110
	 * @see MapsMappingService::getMapId
111
	 *
112
	 * @since 3.0
113
	 */
114
	public function getMapId( $increment = true ) {
115
		static $mapsOnThisPage = 0;
116
117
		if ( $increment ) {
118
			$mapsOnThisPage++;
119
		}
120
121
		return 'map_leaflet_' . $mapsOnThisPage;
122
	}
123
124
	/**
125
	 * @see MapsMappingService::getResourceModules
126
	 *
127
	 * @since 3.0
128
	 *
129
	 * @return array of string
130
	 */
131
	public function getResourceModules() {
132
		return array_merge(
133
			parent::getResourceModules(),
134
			[ 'ext.maps.leaflet' ]
135
		);
136
	}
137
138
}
139