1 | <?php |
||
21 | class SMGeoCoordsValue extends SMWDataValue { |
||
22 | |||
23 | protected $wikiValue; |
||
24 | |||
25 | /** |
||
26 | * @see SMWDataValue::setDataItem |
||
27 | * |
||
28 | * @since 1.0 |
||
29 | * |
||
30 | * @param SMWDataItem $dataItem |
||
31 | * |
||
32 | * @return boolean |
||
33 | */ |
||
34 | 1 | protected function loadDataItem( SMWDataItem $dataItem ) { |
|
47 | |||
48 | /** |
||
49 | * @since 3.0 |
||
50 | * |
||
51 | * @param SMWDIGeoCoord $dataItem |
||
52 | * @param string|null $format |
||
53 | * |
||
54 | * @return string|null |
||
55 | */ |
||
56 | 1 | protected function getFormattedCoord( SMWDIGeoCoord $dataItem, $format = null ) { |
|
74 | |||
75 | /** |
||
76 | * Overwrite SMWDataValue::getQueryDescription() to be able to process |
||
77 | * comparators between all values. |
||
78 | * |
||
79 | * @since 0.6 |
||
80 | * |
||
81 | * @param string $value |
||
82 | * |
||
83 | * @return SMWDescription |
||
84 | * @throws InvalidArgumentException |
||
85 | */ |
||
86 | 6 | public function getQueryDescription( $value ) { |
|
105 | |||
106 | 6 | protected function parserDistance( $distance ) { |
|
118 | |||
119 | /** |
||
120 | * @see SMWDataValue::parseUserValue |
||
121 | * |
||
122 | * @since 0.6 |
||
123 | */ |
||
124 | 6 | protected function parseUserValue( $value ) { |
|
146 | |||
147 | 6 | protected function findValueParts( $value ) { |
|
155 | |||
156 | /** |
||
157 | * @param string $coordinates |
||
158 | */ |
||
159 | 6 | protected function tryParseAndSetDataItem( $coordinates ) { |
|
175 | |||
176 | /** |
||
177 | * @see SMWDataValue::getShortWikiText |
||
178 | * |
||
179 | * @since 0.6 |
||
180 | */ |
||
181 | 1 | public function getShortWikiText( $linked = null ) { |
|
194 | |||
195 | /** |
||
196 | * @see SMWDataValue::getShortHTMLText |
||
197 | * |
||
198 | * @since 0.6 |
||
199 | */ |
||
200 | public function getShortHTMLText( $linker = null ) { |
||
203 | |||
204 | /** |
||
205 | * @see SMWDataValue::getLongWikiText |
||
206 | * |
||
207 | * @since 0.6 |
||
208 | */ |
||
209 | public function getLongWikiText( $linked = null ) { |
||
234 | |||
235 | /** |
||
236 | * @see SMWDataValue::getLongHTMLText |
||
237 | * |
||
238 | * @since 0.6 |
||
239 | */ |
||
240 | public function getLongHTMLText( $linker = null ) { |
||
243 | |||
244 | /** |
||
245 | * @see SMWDataValue::getWikiValue |
||
246 | * |
||
247 | * @since 0.6 |
||
248 | */ |
||
249 | public function getWikiValue() { |
||
252 | |||
253 | /** |
||
254 | * Create links to mapping services based on a wiki-editable message. The parameters |
||
255 | * available to the message are: |
||
256 | * |
||
257 | * $1: The location in non-directional float notation. |
||
258 | * $2: The location in directional DMS notation. |
||
259 | * $3: The latitude in non-directional float notation. |
||
260 | * $4 The longitude in non-directional float notation. |
||
261 | * |
||
262 | * @since 0.6.4 |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | protected function getServiceLinkParams() { |
||
275 | |||
276 | } |
||
277 |
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.