Completed
Push — cln ( 863127...4377d0 )
by Jeroen De
09:58
created

LeafletService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 148
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B addParameterInfo() 0 88 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
namespace Maps;
4
5
use Html;
6
7
/**
8
 * Class holding information and functionality specific to Leaflet.
9
 * This information and features can be used by any mapping feature.
10
 *
11
 * @licence GNU GPL v2+
12
 * @author Pavel Astakhov < [email protected] >
13
 */
14
class LeafletService extends MappingService {
15
16
	public function __construct( $serviceName ) {
17
		parent::__construct(
18
			$serviceName,
19
			[ 'leafletmaps', 'leaflet' ]
20
		);
21
	}
22
23
	/**
24
	 * @see MappingService::addParameterInfo
25
	 *
26
	 * @since 3.0
27
	 */
28
	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...
29
		global $GLOBALS;
30
31
		$params['zoom'] = [
32
			'type' => 'integer',
33
			'range' => [ 0, 20 ],
34
			'default' => false,
35
			'message' => 'maps-par-zoom'
36
		];
37
38
		$params['defzoom'] = [
39
			'type' => 'integer',
40
			'range' => [ 0, 20 ],
41
			'default' => self::getDefaultZoom(),
42
			'message' => 'maps-leaflet-par-defzoom'
43
		];
44
45
		$params['layers'] = [
46
			'aliases' => 'layer',
47
			'type' => 'string',
48
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableLayers'], true, true ),
49
			'default' => $GLOBALS['egMapsLeafletLayers'],
50
			'message' => 'maps-leaflet-par-layers',
51
			'islist' => true,
52
		];
53
54
		$params['overlaylayers'] = [
55
			'type' => 'string',
56
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableOverlayLayers'], true, true ),
57
			'default' => $GLOBALS['egMapsLeafletOverlayLayers'],
58
			'message' => 'maps-leaflet-par-overlaylayers',
59
			'islist' => true,
60
		];
61
62
		$params['resizable'] = [
63
			'type' => 'boolean',
64
			'default' => $GLOBALS['egMapsResizableByDefault'],
65
			'message' => 'maps-par-resizable'
66
		];
67
68
		$params['enablefullscreen'] = [
69
			'type' => 'boolean',
70
			'default' => false,
71
			'message' => 'maps-par-enable-fullscreen',
72
		];
73
74
		$params['scrollwheelzoom'] = [
75
			'type' => 'boolean',
76
			'default' => true,
77
			'message' => 'maps-par-scrollwheelzoom',
78
		];
79
80
		$params['markercluster'] = [
81
			'type' => 'boolean',
82
			'default' => false,
83
			'message' => 'maps-par-markercluster',
84
		];
85
86
		$params['clustermaxzoom'] = [
87
			'type' => 'integer',
88
			'default' => 20,
89
			'message' => 'maps-par-clustermaxzoom',
90
		];
91
92
		$params['clusterzoomonclick'] = [
93
			'type' => 'boolean',
94
			'default' => true,
95
			'message' => 'maps-par-clusterzoomonclick',
96
		];
97
98
		$params['clustermaxradius'] = [
99
			'type' => 'integer',
100
			'default' => 80,
101
			'message' => 'maps-par-maxclusterradius',
102
		];
103
104
		$params['clusterspiderfy'] = [
105
			'type' => 'boolean',
106
			'default' => true,
107
			'message' => 'maps-leaflet-par-clusterspiderfy',
108
		];
109
110
		$params['geojson'] = [
111
			'type' => 'jsonfile',
112
			'default' => '',
113
			'message' => 'maps-displaymap-par-geojson',
114
		];
115
	}
116
117
	/**
118
	 * @since 3.0
119
	 */
120
	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...
121
		return $GLOBALS['egMapsLeafletZoom'];
122
	}
123
124
	/**
125
	 * @see MappingService::getMapId
126
	 *
127
	 * @since 3.0
128
	 */
129
	public function getMapId( $increment = true ) {
130
		static $mapsOnThisPage = 0;
131
132
		if ( $increment ) {
133
			$mapsOnThisPage++;
134
		}
135
136
		return 'map_leaflet_' . $mapsOnThisPage;
137
	}
138
139
	/**
140
	 * @see MappingService::getResourceModules
141
	 *
142
	 * @since 3.0
143
	 *
144
	 * @return string[]
145
	 */
146
	public function getResourceModules() {
147
		return array_merge(
148
			parent::getResourceModules(),
149
			[ 'ext.maps.leaflet' ]
150
		);
151
	}
152
153
	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...
154
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/includes/services/Leaflet/leaflet';
155
		return [
156
			Html::linkedStyle( "$leafletPath/leaflet.css" ),
157
			Html::linkedScript( "$leafletPath/leaflet.js" ),
158
		];
159
	}
160
161
}
162