Completed
Push — wtfrl ( 278ac8 )
by Jeroen De
05:05
created

MapsLeaflet::getResourceModules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
	public function __construct( $serviceName ) {
13
		parent::__construct(
14
			$serviceName,
15
			[ 'leafletmaps', 'leaflet' ]
16
		);
17
	}
18
19
	/**
20
	 * @see MapsMappingService::addParameterInfo
21
	 *
22
	 * @since 3.0
23
	 */
24 12
	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...
25 12
		global $GLOBALS;
26
27 12
		$params['zoom'] = [
28
			'type' => 'integer',
29
			'range' => [ 0, 20 ],
30
			'default' => false,
31
			'message' => 'maps-par-zoom'
32
		];
33
34 12
		$params['defzoom'] = [
35 12
			'type' => 'integer',
36
			'range' => [ 0, 20 ],
37 12
			'default' => self::getDefaultZoom(),
38 12
			'message' => 'maps-leaflet-par-defzoom'
39
		];
40
41 12
		$params['layers'] = [
42 12
			'aliases' => 'layer',
43 12
			'type' => 'string',
44 12
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableLayers'], true, true ),
45 12
			'default' => $GLOBALS['egMapsLeafletLayers'],
46 12
			'message' => 'maps-leaflet-par-layers',
47
			'islist' => true,
48
		];
49
50 12
		$params['overlaylayers'] = [
51 12
			'type' => 'string',
52 12
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableOverlayLayers'], true, true ),
53 12
			'default' => $GLOBALS['egMapsLeafletOverlayLayers'],
54 12
			'message' => 'maps-leaflet-par-overlaylayers',
55
			'islist' => true,
56
		];
57
58 12
		$params['resizable'] = [
59 12
			'type' => 'boolean',
60 12
			'default' => $GLOBALS['egMapsResizableByDefault'],
61 12
			'message' => 'maps-par-resizable'
62
		];
63
64 12
		$params['enablefullscreen'] = [
65
			'type' => 'boolean',
66
			'default' => false,
67
			'message' => 'maps-par-enable-fullscreen',
68
		];
69
70 12
		$params['scrollwheelzoom'] = [
71
			'type' => 'boolean',
72
			'default' => true,
73
			'message' => 'maps-par-scrollwheelzoom',
74
		];
75
76 12
		$params['markercluster'] = [
77
			'type' => 'boolean',
78
			'default' => false,
79
			'message' => 'maps-par-markercluster',
80
		];
81
82 12
		$params['clustermaxzoom'] = [
83
			'type' => 'integer',
84
			'default' => 20,
85
			'message' => 'maps-par-clustermaxzoom',
86
		];
87
88 12
		$params['clusterzoomonclick'] = [
89
			'type' => 'boolean',
90
			'default' => true,
91
			'message' => 'maps-par-clusterzoomonclick',
92
		];
93
94 12
		$params['clustermaxradius'] = [
95
			'type' => 'integer',
96
			'default' => 80,
97
			'message' => 'maps-par-maxclusterradius',
98
		];
99
100 12
		$params['clusterspiderfy'] = [
101
			'type' => 'boolean',
102
			'default' => true,
103
			'message' => 'maps-leaflet-par-clusterspiderfy',
104
		];
105
106 12
		$params['geojson'] = [
107
			'type' => 'jsonfile',
108
			'default' => '',
109
			'message' => 'maps-displaymap-par-geojson',
110
		];
111 12
	}
112
113
	/**
114
	 * @since 3.0
115
	 */
116 12
	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...
117 12
		return $GLOBALS['egMapsLeafletZoom'];
118
	}
119
120
	/**
121
	 * @see MapsMappingService::getMapId
122
	 *
123
	 * @since 3.0
124
	 */
125 12
	public function getMapId( $increment = true ) {
126 12
		static $mapsOnThisPage = 0;
127
128 12
		if ( $increment ) {
129 12
			$mapsOnThisPage++;
130
		}
131
132 12
		return 'map_leaflet_' . $mapsOnThisPage;
133
	}
134
135
	/**
136
	 * @see MapsMappingService::getResourceModules
137
	 *
138
	 * @since 3.0
139
	 *
140
	 * @return string[]
141
	 */
142 12
	public function getResourceModules() {
143 12
		return array_merge(
144 12
			parent::getResourceModules(),
145 12
			[ 'ext.maps.leaflet' ]
146
		);
147
	}
148
149 12
	protected function getDependencies() {
0 ignored issues
show
Coding Style introduced by
getDependencies 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...
150 12
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/includes/services/Leaflet/leaflet';
151
		return [
152 12
			Html::linkedStyle( "$leafletPath/leaflet.css" ),
153 12
			Html::linkedScript( "$leafletPath/leaflet.js" ),
154
		];
155
	}
156
157
}
158