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

OpenLayersService::addParameterInfo()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 8.7636
c 0
b 0
f 0
cc 1
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Maps;
4
5
/**
6
 * Class holding information and functionality specific to OpenLayers.
7
 * This information and features can be used by any mapping feature.
8
 *
9
 * @since 0.1
10
 *
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class OpenLayersService extends MappingService {
15
16
	public function __construct( $serviceName ) {
17
		parent::__construct(
18
			$serviceName,
19
			[ 'layers', 'openlayer' ]
20
		);
21
	}
22
23
	/**
24
	 * Returns the names of all supported dynamic layers.
25
	 *
26
	 * @param boolean $includeGroups
27
	 *
28
	 * @return array
29
	 */
30
	public static function getLayerNames( $includeGroups = false ) {
31
		global $egMapsOLAvailableLayers, $egMapsOLLayerGroups;
32
33
		$keys = array_keys( $egMapsOLAvailableLayers );
34
35
		if ( $includeGroups ) {
36
			$keys = array_merge( $keys, array_keys( $egMapsOLLayerGroups ) );
37
		}
38
39
		return $keys;
40
	}
41
42
	/**
43
	 * @see MappingService::addParameterInfo
44
	 */
45
	public function addParameterInfo( array &$params ) {
46
		global $egMapsOLLayers, $egMapsOLControls, $egMapsResizableByDefault;
47
48
		$params['zoom'] = [
49
			'type' => 'integer',
50
			'range' => [ 0, 19 ],
51
			'default' => self::getDefaultZoom(),
52
			'message' => 'maps-par-zoom',
53
		];
54
55
		$params['controls'] = [
56
			'default' => $egMapsOLControls,
57
			'values' => self::getControlNames(),
58
			'message' => 'maps-openlayers-par-controls',
59
			'islist' => true,
60
			'tolower' => true,
61
		];
62
63
		$params['layers'] = [
64
			'default' => $egMapsOLLayers,
65
			'message' => 'maps-openlayers-par-layers',
66
			'manipulatedefault' => true,
67
			'islist' => true,
68
			'tolower' => true,
69
			// TODO-customMaps: addCriteria( new CriterionOLLayer() );
70
		];
71
72
		$params['resizable'] = [
73
			'type' => 'boolean',
74
			'default' => false,
75
			'manipulatedefault' => false,
76
			'message' => 'maps-par-resizable',
77
		];
78
79
		$params['overlays'] = [
80
			// Default empty array will end up in JS just right without manipulation.
81
			'default' => [],
82
			'manipulatedefault' => false,
83
			'message' => 'maps-openlayers-par-overlays',
84
85
			// NOTE: code has moved into @see Maps\MediaWiki\ParserHooks\MapsDisplayMapRenderer
86
			// TODO-customMaps: addCriteria( new CriterionOLLayer( ';' ) );
87
			// TODO-customMaps: addManipulations( new MapsParamOLLayers() );
88
		];
89
90
		$params['resizable'] = [
91
			'type' => 'boolean',
92
			'default' => $egMapsResizableByDefault,
93
			'message' => 'maps-par-resizable',
94
		];
95
96
		$params['searchmarkers'] = [
97
			'default' => '',
98
			'message' => 'maps-par-searchmarkers',
99
			'values' => [ 'title', 'all', '' ],
100
			'tolower' => true,
101
		];
102
103
		$params['kml'] = [
104
			'default' => [],
105
			'message' => 'maps-par-kml',
106
			'islist' => true,
107
			// new MapsParamFile() FIXME
108
		];
109
	}
110
111
	/**
112
	 * @since 0.6.5
113
	 */
114
	public function getDefaultZoom() {
115
		global $egMapsOpenLayersZoom;
116
		return $egMapsOpenLayersZoom;
117
	}
118
119
	/**
120
	 * Returns the names of all supported controls.
121
	 * This data is a copy of the one used to actually translate the names
122
	 * into the controls, since this resides client side, in OpenLayerFunctions.js.
123
	 *
124
	 * @return array
125
	 */
126
	public static function getControlNames() {
127
		return [
128
			'argparser',
129
			'attribution',
130
			'button',
131
			'dragfeature',
132
			'dragpan',
133
			'drawfeature',
134
			'editingtoolbar',
135
			'getfeature',
136
			'keyboarddefaults',
137
			'layerswitcher',
138
			'measure',
139
			'modifyfeature',
140
			'mousedefaults',
141
			'mouseposition',
142
			'mousetoolbar',
143
			'navigation',
144
			'navigationhistory',
145
			'navtoolbar',
146
			'overviewmap',
147
			'pan',
148
			'panel',
149
			'panpanel',
150
			'panzoom',
151
			'panzoombar',
152
			'autopanzoom',
153
			'permalink',
154
			'scale',
155
			'scaleline',
156
			'selectfeature',
157
			'snapping',
158
			'split',
159
			'wmsgetfeatureinfo',
160
			'zoombox',
161
			'zoomin',
162
			'zoomout',
163
			'zoompanel',
164
			'zoomtomaxextent'
165
		];
166
	}
167
168
	/**
169
	 * @see MappingService::getMapId
170
	 *
171
	 * @since 0.6.5
172
	 */
173
	public function getMapId( $increment = true ) {
174
		static $mapsOnThisPage = 0;
175
176
		if ( $increment ) {
177
			$mapsOnThisPage++;
178
		}
179
180
		return 'open_layer_' . $mapsOnThisPage;
181
	}
182
183
	/**
184
	 * @see MappingService::getResourceModules
185
	 *
186
	 * @since 0.7.3
187
	 *
188
	 * @return array of string
189
	 */
190
	public function getResourceModules() {
191
		return array_merge(
192
			parent::getResourceModules(),
193
			[ 'ext.maps.openlayers' ]
194
		);
195
	}
196
197
}
198