Completed
Push — leaflet-fullscreen-load ( 08cef4...3c7f7c )
by Peter
11:46 queued 06:37
created

MapsLeaflet   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 0 Features 3
Metric Value
c 7
b 0
f 3
dl 0
loc 122
ccs 0
cts 64
cp 0
rs 10
wmc 7
lcom 0
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addParameterInfo() 0 57 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
/**
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-par-maxclusterradius',
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