Completed
Push — master ( 684184...9a35aa )
by Jeroen De
08:07
created

includes/parserhooks/Maps_Distance.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Class for the 'distance' parser hooks, 
5
 * which can transform the notation of a distance.
6
 * 
7
 * @since 0.7
8
 * 
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class MapsDistance extends ParserHook {
0 ignored issues
show
Deprecated Code introduced by
The class ParserHook has been deprecated with message: since 1.0 in favour of the ParserHooks library

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
13
14
	/**
15
	 * Gets the name of the parser hook.
16
	 * @see ParserHook::getName
17
	 * 
18
	 * @since 0.7
19
	 * 
20
	 * @return string
21
	 */
22
	protected function getName() {
23
		return 'distance';
24
	}
25
	
26
	/**
27
	 * Returns an array containing the parameter info.
28
	 * @see ParserHook::getParameterInfo
29
	 * 
30
	 * @since 0.7
31
	 * 
32
	 * @return array
33
	 */
34
	protected function getParameterInfo( $type ) {
35
		global $egMapsDistanceUnit, $egMapsDistanceDecimals; 
36
		
37
		$params = [];
38
39
		$params['distance'] = [
40
			'type' => 'distance',
41
		];
42
43
		$params['unit'] = [
44
			'default' => $egMapsDistanceUnit,
45
			'values' => MapsDistanceParser::getUnits(),
46
		];
47
48
		$params['decimals'] = [
49
			'type' => 'integer',
50
			'default' => $egMapsDistanceDecimals,
51
		];
52
53
		// Give grep a chance to find the usages:
54
		// maps-distance-par-distance, maps-distance-par-unit, maps-distance-par-decimals
55
		foreach ( $params as $name => &$param ) {
56
			$param['message'] = 'maps-distance-par-' . $name;
57
		}
58
59
		return $params;
60
	}
61
	
62
	/**
63
	 * Returns the list of default parameters.
64
	 * @see ParserHook::getDefaultParameters
65
	 * 
66
	 * @since 0.7
67
	 *
68
	 * @param $type
69
	 * 
70
	 * @return array
71
	 */
72
	protected function getDefaultParameters( $type ) {
73
		return [ 'distance', 'unit', 'decimals' ];
74
	}
75
	
76
	/**
77
	 * Renders and returns the output.
78
	 * @see ParserHook::render
79
	 * 
80
	 * @since 0.7
81
	 * 
82
	 * @param array $parameters
83
	 * 
84
	 * @return string
85
	 */
86
	public function render( array $parameters ) {
87
		return MapsDistanceParser::formatDistance(
88
			$parameters['distance'],
89
			$parameters['unit'],
90
			$parameters['decimals']
91
		);
92
	}
93
94
	/**
95
	 * @see ParserHook::getMessage()
96
	 * 
97
	 * @since 1.0
98
	 */
99
	public function getMessage() {
100
		return 'maps-distance-description';
101
	}		
102
	
103
}