Completed
Push — cleanz ( f1882e...25c139 )
by Jeroen De
27:32 queued 25:40
created

MapsLeaflet   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90.2%

Importance

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