Completed
Push — master ( 4dbba6...2bc122 )
by Jeroen De
03:56
created

MapsFunctions::encodeJsVar()   C

Complexity

Conditions 15
Paths 7

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 0
cts 26
cp 0
rs 5.9166
c 0
b 0
f 0
cc 15
nc 7
nop 1
crap 240

How to fix   Complexity   

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
 * A class that holds static helper functions for generic mapping-related functions.
7
 *
8
 * @deprecated
9
 *
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
final class MapsFunctions {
14
15
	/**
16
	 * This function returns the definitions for the parameters used by every map feature.
17
	 *
18
	 * @return array
19
	 */
20 26
	public static function getCommonParameters() {
21 26
		$params = [];
22
23 26
		$params['width'] = [
24 26
			'type' => 'dimension',
25
			'allowauto' => true,
26
			'units' => [ 'px', 'ex', 'em', '%', '' ],
27 26
			'default' => $GLOBALS['egMapsMapWidth'],
28 26
			'message' => 'maps-par-width',
29
		];
30
31 26
		$params['height'] = [
32 26
			'type' => 'dimension',
33
			'units' => [ 'px', 'ex', 'em', '' ],
34 26
			'default' => $GLOBALS['egMapsMapHeight'],
35 26
			'message' => 'maps-par-height',
36
		];
37
38 26
		$params['centre'] = [
39
			'type' => 'string',
40
			'aliases' => [ 'center' ],
41
			'default' => false,
42
			'manipulatedefault' => false,
43
			'message' => 'maps-par-centre',
44
		];
45
46 26
		$params['title'] = [
47 26
			'name' => 'title',
48 26
			'default' => $GLOBALS['egMapsDefaultTitle'],
49
		];
50
51 26
		$params['label'] = [
52 26
			'default' => $GLOBALS['egMapsDefaultLabel'],
53 26
			'aliases' => 'text',
54
		];
55
56 26
		$params['icon'] = [
57
			'default' => '',
58
		];
59
60 26
		$params['lines'] = [
61
			'type' => 'mapsline',
62
			'default' => [],
63
			'delimiter' => ';',
64
			'islist' => true,
65
		];
66
67 26
		$params['polygons'] = [
68
			'type' => 'mapspolygon',
69
			'default' => [],
70
			'delimiter' => ';',
71
			'islist' => true,
72
		];
73
74 26
		$params['circles'] = [
75
			'type' => 'mapscircle',
76
			'default' => [],
77
			'delimiter' => ';',
78
			'islist' => true,
79
		];
80
81 26
		$params['rectangles'] = [
82
			'type' => 'mapsrectangle',
83
			'default' => [],
84
			'delimiter' => ';',
85
			'islist' => true,
86
		];
87
88 26
		$params['maxzoom'] = [
89
			'type' => 'integer',
90
			'default' => false,
91
			'manipulatedefault' => false,
92
			'dependencies' => 'minzoom',
93
		];
94
95 26
		$params['minzoom'] = [
96
			'type' => 'integer',
97
			'default' => false,
98
			'manipulatedefault' => false,
99
			'lowerbound' => 0,
100
		];
101
102 26
		$params['copycoords'] = [
103
			'type' => 'boolean',
104
			'default' => false,
105
		];
106
107 26
		$params['static'] = [
108
			'type' => 'boolean',
109
			'default' => false,
110
		];
111
112
		// Give grep a chance to find the usages:
113
		// maps-displaymap-par-title, maps-displaymap-par-label, maps-displaymap-par-icon,
114
		// aps-displaymap-par-lines, maps-displaymap-par-polygons,
115
		// maps-displaymap-par-circles, maps-displaymap-par-rectangles,
116
		// maps-displaymap-par-maxzoom, maps-displaymap-par-minzoom, maps-displaymap-par-copycoords,
117
		// maps-displaymap-par-static
118 26
		foreach ( $params as $name => &$param ) {
119 26
			if ( !array_key_exists( 'message', $param ) ) {
120 26
				$param['message'] = 'maps-displaymap-par-' . $name;
121
			}
122
		}
123
124 26
		return $params;
125
	}
126
127
	/**
128
	 * Resolves the url of images provided as wiki page; leaves others alone.
129
	 *
130
	 * @since 1.0
131
	 * @deprecated
132
	 *
133
	 * @param string $file
134
	 *
135
	 * @return string
136
	 */
137 5
	public static function getFileUrl( $file ): string {
138 5
		return MapsFactory::globalInstance()->getFileUrlFinder()->getUrlForFileName( $file );
139
	}
140
141
}
142