Completed
Pull Request — master (#394)
by Peter
04:13
created

MapsLeaflet   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 136
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B addParameterInfo() 0 76 1
A getDefaultZoom() 0 3 1
A getMapId() 0 9 2
A getResourceModules() 0 6 1
A getDependencies() 0 7 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
	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
		global $GLOBALS;
26
27
		$params['zoom'] = [
28
			'type' => 'integer',
29
			'range' => [ 0, 20 ],
30
			'default' => false,
31
			'message' => 'maps-par-zoom'
32
		];
33
34
		$params['defzoom'] = [
35
			'type' => 'integer',
36
			'range' => [ 0, 20 ],
37
			'default' => self::getDefaultZoom(),
38
			'message' => 'maps-leaflet-par-defzoom'
39
		];
40
41
		$params['layers'] = [
42
			'aliases' => 'layer',
43
			'type' => 'string',
44
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableLayers'], true, true ),
45
			'default' => $GLOBALS['egMapsLeafletLayers'],
46
			'message' => 'maps-leaflet-par-layer',
47
			'islist' => true,
48
		];
49
50
		$params['overlaylayers'] = [
51
			'type' => 'string',
52
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableOverlayLayers'], true, true ),
53
			'default' => $GLOBALS['egMapsLeafletOverlayLayers'],
54
			'message' => 'maps-leaflet-par-overlaylayers',
55
			'islist' => true,
56
		];
57
58
		$params['resizable'] = [
59
			'type' => 'boolean',
60
			'default' => $GLOBALS['egMapsResizableByDefault'],
61
			'message' => 'maps-par-resizable'
62
		];
63
64
		$params['enablefullscreen'] = [
65
			'type' => 'boolean',
66
			'default' => false,
67
			'message' => 'maps-par-enable-fullscreen',
68
		];
69
70
		$params['markercluster'] = [
71
			'type' => 'boolean',
72
			'default' => false,
73
			'message' => 'maps-par-markercluster',
74
		];
75
76
		$params['clustermaxzoom'] = [
77
			'type' => 'integer',
78
			'default' => 20,
79
			'message' => 'maps-par-clustermaxzoom',
80
		];
81
82
		$params['clusterzoomonclick'] = [
83
			'type' => 'boolean',
84
			'default' => true,
85
			'message' => 'maps-par-clusterzoomonclick',
86
		];
87
88
		$params['clustermaxradius'] = [
89
			'type' => 'integer',
90
			'default' => 80,
91
			'message' => 'maps-par-maxclusterradius',
92
		];
93
94
		$params['clusterspiderfy'] = [
95
			'type' => 'boolean',
96
			'default' => true,
97
			'message' => 'maps-leaflet-par-clusterspiderfy',
98
		];
99
	}
100
101
	/**
102
	 * @since 3.0
103
	 */
104
	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...
105
		return $GLOBALS['egMapsLeafletZoom'];
106
	}
107
108
	/**
109
	 * @see MapsMappingService::getMapId
110
	 *
111
	 * @since 3.0
112
	 */
113
	public function getMapId( $increment = true ) {
114
		static $mapsOnThisPage = 0;
115
116
		if ( $increment ) {
117
			$mapsOnThisPage++;
118
		}
119
120
		return 'map_leaflet_' . $mapsOnThisPage;
121
	}
122
123
	/**
124
	 * @see MapsMappingService::getResourceModules
125
	 *
126
	 * @since 3.0
127
	 *
128
	 * @return array of string
129
	 */
130
	public function getResourceModules() {
131
		return array_merge(
132
			parent::getResourceModules(),
133
			[ 'ext.maps.leaflet' ]
134
		);
135
	}
136
137
	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...
138
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/includes/services/Leaflet/leaflet';
139
		return [
140
			Html::linkedStyle( "$leafletPath/leaflet.css" ),
141
			Html::linkedScript( "$leafletPath/leaflet.js" ),
142
		];
143
	}
144
145
}
146