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 'display_map' parser hooks. |
||
5 | * |
||
6 | * @since 0.7 |
||
7 | * |
||
8 | * @licence GNU GPL v2+ |
||
9 | * @author Jeroen De Dauw < [email protected] > |
||
10 | */ |
||
11 | class MapsDisplayMap extends ParserHook { |
||
12 | |||
13 | /** |
||
14 | * Gets the name of the parser hook. |
||
15 | * @see ParserHook::getName |
||
16 | * |
||
17 | * @since 0.7 |
||
18 | * |
||
19 | * @return string |
||
20 | */ |
||
21 | protected function getName() { |
||
22 | return 'display_map'; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @see ParserHook::getNames() |
||
27 | * |
||
28 | * @since 2.0 |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | protected function getNames() { |
||
33 | return [ $this->getName(), 'display_point', 'display_points', 'display_line' ]; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Returns an array containing the parameter info. |
||
38 | * @see ParserHook::getParameterInfo |
||
39 | * |
||
40 | * @since 0.7 |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | protected function getParameterInfo( $type ) { |
||
45 | $params = MapsMapper::getCommonParameters(); |
||
46 | |||
47 | $params['mappingservice']['feature'] = 'display_map'; |
||
48 | |||
49 | $params['coordinates'] = [ |
||
50 | 'type' => 'mapslocation', |
||
51 | 'aliases' => [ 'coords', 'location', 'address', 'addresses', 'locations', 'points' ], |
||
52 | 'dependencies' => [ 'mappingservice', 'geoservice' ], |
||
53 | 'default' => [], |
||
54 | 'islist' => true, |
||
55 | 'delimiter' => $type === ParserHook::TYPE_FUNCTION ? ';' : "\n", |
||
56 | 'message' => 'maps-displaymap-par-coordinates', |
||
57 | ]; |
||
58 | |||
59 | $params = array_merge( $params, self::getCommonMapParams() ); |
||
60 | |||
61 | return $params; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Temporary hack. Do not rely upon. |
||
66 | * @since 3.0 |
||
67 | * @deprecated |
||
68 | * @return array |
||
69 | */ |
||
70 | public static function getCommonMapParams() { |
||
71 | global $egMapsDefaultTitle, $egMapsDefaultLabel; |
||
72 | |||
73 | $params['title'] = [ |
||
74 | 'name' => 'title', |
||
75 | 'default' => $egMapsDefaultTitle, |
||
76 | ]; |
||
77 | |||
78 | $params['label'] = [ |
||
79 | 'default' => $egMapsDefaultLabel, |
||
80 | 'aliases' => 'text', |
||
81 | ]; |
||
82 | |||
83 | $params['icon'] = [ |
||
84 | 'default' => '', // TODO: image param |
||
85 | ]; |
||
86 | |||
87 | $params['visitedicon'] = [ |
||
88 | 'default' => '', //TODO: image param |
||
89 | ]; |
||
90 | |||
91 | $params['lines'] = [ |
||
92 | 'type' => 'mapsline', |
||
93 | 'default' => [], |
||
94 | 'delimiter' => ';', |
||
95 | 'islist' => true, |
||
96 | ]; |
||
97 | |||
98 | $params['polygons'] = [ |
||
99 | 'type' => 'mapspolygon', |
||
100 | 'default' => [], |
||
101 | 'delimiter' => ';', |
||
102 | 'islist' => true, |
||
103 | ]; |
||
104 | |||
105 | $params['circles'] = [ |
||
106 | 'type' => 'mapscircle', |
||
107 | 'default' => [], |
||
108 | 'delimiter' => ';', |
||
109 | 'islist' => true, |
||
110 | ]; |
||
111 | |||
112 | $params['rectangles'] = [ |
||
113 | 'type' => 'mapsrectangle', |
||
114 | 'default' => [], |
||
115 | 'delimiter' => ';', |
||
116 | 'islist' => true, |
||
117 | ]; |
||
118 | |||
119 | $params['wmsoverlay'] = [ |
||
120 | 'type' => 'wmsoverlay', |
||
121 | 'default' => false, |
||
122 | 'delimiter' => ' ', |
||
123 | ]; |
||
124 | |||
125 | $params['maxzoom'] = [ |
||
126 | 'type' => 'integer', |
||
127 | 'default' => false, |
||
128 | 'manipulatedefault' => false, |
||
129 | 'dependencies' => 'minzoom', |
||
130 | ]; |
||
131 | |||
132 | $params['minzoom'] = [ |
||
133 | 'type' => 'integer', |
||
134 | 'default' => false, |
||
135 | 'manipulatedefault' => false, |
||
136 | 'lowerbound' => 0, |
||
137 | ]; |
||
138 | |||
139 | $params['copycoords'] = [ |
||
140 | 'type' => 'boolean', |
||
141 | 'default' => false, |
||
142 | ]; |
||
143 | |||
144 | $params['static'] = [ |
||
145 | 'type' => 'boolean', |
||
146 | 'default' => false, |
||
147 | ]; |
||
148 | |||
149 | // Give grep a chance to find the usages: |
||
150 | // maps-displaymap-par-title, maps-displaymap-par-label, maps-displaymap-par-icon, |
||
151 | // maps-displaymap-par-visitedicon, aps-displaymap-par-lines, maps-displaymap-par-polygons, |
||
152 | // maps-displaymap-par-circles, maps-displaymap-par-rectangles, maps-displaymap-par-wmsoverlay, |
||
153 | // maps-displaymap-par-maxzoom, maps-displaymap-par-minzoom, maps-displaymap-par-copycoords, |
||
154 | // maps-displaymap-par-static |
||
155 | foreach ( $params as $name => &$param ) { |
||
156 | if ( !array_key_exists( 'message', $param ) ) { |
||
157 | $param['message'] = 'maps-displaymap-par-' . $name; |
||
158 | } |
||
159 | } |
||
160 | |||
161 | return $params; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Returns the list of default parameters. |
||
166 | * @see ParserHook::getDefaultParameters |
||
167 | * |
||
168 | * @since 0.7 |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | protected function getDefaultParameters( $type ) { |
||
173 | return [ 'coordinates' ]; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * Renders and returns the output. |
||
178 | * @see ParserHook::render |
||
179 | * |
||
180 | * @since 0.7 |
||
181 | * |
||
182 | * @param array $parameters |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | public function render( array $parameters ) { |
||
187 | // Get the instance of the service class. |
||
188 | $service = MapsMappingServices::getServiceInstance( $parameters['mappingservice'] ); |
||
189 | |||
190 | $mapClass = new MapsDisplayMapRenderer( $service ); |
||
191 | |||
192 | $fullParams = $this->validator->getParameters(); |
||
193 | |||
194 | if ( array_key_exists( 'zoom', $fullParams ) && $fullParams['zoom']->wasSetToDefault() && count( $parameters['coordinates'] ) > 1 ) { |
||
195 | $parameters['zoom'] = false; |
||
196 | } |
||
197 | |||
198 | global $egMapsEnableCategory; |
||
199 | if ($egMapsEnableCategory) { |
||
200 | $this->parser->addTrackingCategory( 'maps-tracking-category' ); |
||
201 | } |
||
202 | return $mapClass->renderMap( $parameters, $this->parser ); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Returns the parser function options. |
||
207 | * @see ParserHook::getFunctionOptions |
||
208 | * |
||
209 | * @since 0.7 |
||
210 | * |
||
211 | * @return array |
||
212 | */ |
||
213 | protected function getFunctionOptions() { |
||
214 | return [ |
||
215 | 'noparse' => true, |
||
216 | 'isHTML' => true |
||
217 | ]; |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * @see ParserHook::getMessage() |
||
222 | * |
||
223 | * @since 1.0 |
||
224 | */ |
||
225 | public function getMessage() { |
||
226 | return 'maps-displaymap-description'; |
||
0 ignored issues
–
show
|
|||
227 | } |
||
228 | |||
229 | } |
||
230 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.