Completed
Push — leaflet-fullscreen ( bc410b )
by Peter
03:48
created

MapsLeaflet::addParameterInfo()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 1
eloc 19
c 4
b 0
f 1
nc 1
nop 1
dl 0
loc 27
ccs 0
cts 20
cp 0
crap 2
rs 8.8571
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
55
	/**
56
	 * @see iMappingService::getDefaultZoom
57
	 *
58
	 * @since 3.0
59
	 */
60
	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...
61
		return $GLOBALS['egMapsLeafletZoom'];
62
	}
63
64
	/**
65
	 * @see MapsMappingService::getMapId
66
	 *
67
	 * @since 3.0
68
	 */
69
	public function getMapId( $increment = true ) {
70
		static $mapsOnThisPage = 0;
71
72
		if ( $increment ) {
73
			$mapsOnThisPage++;
74
		}
75
76
		return 'map_leaflet_' . $mapsOnThisPage;
77
	}
78
79
	/**
80
	 * @see MapsMappingService::getResourceModules
81
	 *
82
	 * @since 3.0
83
	 *
84
	 * @return array of string
85
	 */
86
	public function getResourceModules() {
87
		return array_merge(
88
			parent::getResourceModules(),
89
			[ 'ext.maps.leaflet' ]
90
		);
91
	}
92
93
	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...
94
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/includes/services/Leaflet/leaflet';
95
		return [
96
			Html::linkedStyle( "$leafletPath/leaflet.css" ),
97
			Html::linkedScript( "$leafletPath/leaflet.js" ),
98
		];
99
	}
100
101
}
102