Completed
Push — leaflet-cluster ( f0eec4...6bb6c6 )
by Peter
07:12
created

MapsLeaflet::addParameterInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 6
Bugs 0 Features 3
Metric Value
cc 1
eloc 39
c 6
b 0
f 3
nc 1
nop 1
dl 0
loc 57
ccs 0
cts 40
cp 0
crap 2
rs 9.6818

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
/**
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
	/**
13
	 * Constructor
14
	 */
15
	public function __construct( $serviceName ) {
16
		parent::__construct(
17
			$serviceName,
18
			[ 'leafletmaps', 'leaflet' ]
19
		);
20
	}
21
22
	/**
23
	 * @see MapsMappingService::addParameterInfo
24
	 *
25
	 * @since 3.0
26
	 */
27
	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...
28
		$params['zoom'] = [
29
			'type' => 'integer',
30
			'range' => [ 0, 20 ],
31
			'default' => false,
32
			'message' => 'maps-par-zoom'
33
		];
34
35
		$params['defzoom'] = [
36
			'type' => 'integer',
37
			'range' => [ 0, 20 ],
38
			'default' => self::getDefaultZoom(),
39
			'message' => 'maps-leaflet-par-defzoom'
40
		];
41
42
		$params['resizable'] = [
43
			'type' => 'boolean',
44
			'default' => $GLOBALS['egMapsResizableByDefault'],
45
			'message' => 'maps-par-resizable'
46
		];
47
48
		$params['enablefullscreen'] = [
49
			'type' => 'boolean',
50
			'default' => false,
51
			'message' => 'maps-par-enable-fullscreen',
52
		];
53
54
		$params['markercluster'] = [
55
			'type' => 'boolean',
56
			'default' => false,
57
			'message' => 'maps-par-markercluster',
58
		];
59
60
		$params['clustermaxzoom'] = [
61
			'type' => 'integer',
62
			'default' => 20,
63
			'message' => 'maps-par-clustermaxzoom',
64
		];
65
66
		$params['clusterzoomonclick'] = [
67
			'type' => 'boolean',
68
			'default' => true,
69
			'message' => 'maps-par-clusterzoomonclick',
70
		];
71
72
		$params['clustermaxradius'] = [
73
			'type' => 'integer',
74
			'default' => 80,
75
			'message' => 'maps-leaflet-par-clustermaxzoom',
76
		];
77
78
		$params['clusterspiderfy'] = [
79
			'type' => 'boolean',
80
			'default' => true,
81
			'message' => 'maps-leaflet-par-clusterspiderfy',
82
		];
83
	}
84
85
	/**
86
	 * @see iMappingService::getDefaultZoom
87
	 *
88
	 * @since 3.0
89
	 */
90
	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...
91
		return $GLOBALS['egMapsLeafletZoom'];
92
	}
93
94
	/**
95
	 * @see MapsMappingService::getMapId
96
	 *
97
	 * @since 3.0
98
	 */
99
	public function getMapId( $increment = true ) {
100
		static $mapsOnThisPage = 0;
101
102
		if ( $increment ) {
103
			$mapsOnThisPage++;
104
		}
105
106
		return 'map_leaflet_' . $mapsOnThisPage;
107
	}
108
109
	/**
110
	 * @see MapsMappingService::getResourceModules
111
	 *
112
	 * @since 3.0
113
	 *
114
	 * @return array of string
115
	 */
116
	public function getResourceModules() {
117
		return array_merge(
118
			parent::getResourceModules(),
119
			[ 'ext.maps.leaflet' ]
120
		);
121
	}
122
123
	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...
124
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/includes/services/Leaflet/leaflet';
125
		return [
126
			Html::linkedStyle( "$leafletPath/leaflet.css" ),
127
			Html::linkedScript( "$leafletPath/leaflet.js" ),
128
		];
129
	}
130
131
}
132