1 | <?php |
||
25 | class GeocoderProvider extends AbstractService implements LocaleAwareProvider |
||
26 | { |
||
27 | use LocaleTrait; |
||
28 | |||
29 | /** |
||
30 | * @var int|null |
||
31 | */ |
||
32 | private $limit; |
||
33 | |||
34 | /** |
||
35 | * @param HttpClient $client |
||
36 | * @param MessageFactory $messageFactory |
||
37 | */ |
||
38 | public function __construct(HttpClient $client, MessageFactory $messageFactory) |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function getLimit() |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function limit($limit) |
||
60 | |||
61 | /** |
||
62 | * @param AbstractGeocoderRequest|Coordinate|string $request |
||
63 | * |
||
64 | * @return GeocoderResponse |
||
65 | */ |
||
66 | public function geocode($request) |
||
85 | |||
86 | /** |
||
87 | * @param float $latitude |
||
88 | * @param float $longitude |
||
89 | * |
||
90 | * @return GeocoderResponse |
||
91 | */ |
||
92 | public function reverse($latitude, $longitude) |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function getName() |
||
104 | |||
105 | /** |
||
106 | * @param string $data |
||
107 | * |
||
108 | * @return mixed[] |
||
109 | */ |
||
110 | private function parse($data) |
||
122 | |||
123 | /** |
||
124 | * @param mixed[] $data |
||
125 | * |
||
126 | * @return GeocoderResponse |
||
127 | */ |
||
128 | private function buildResponse(array $data) |
||
136 | |||
137 | /** |
||
138 | * @param mixed[] $data |
||
139 | * |
||
140 | * @return GeocoderResult[] |
||
141 | */ |
||
142 | private function buildResults(array $data) |
||
156 | |||
157 | /** |
||
158 | * @param mixed[] $data |
||
159 | * |
||
160 | * @return GeocoderResult |
||
161 | */ |
||
162 | private function buildResult(array $data) |
||
174 | |||
175 | /** |
||
176 | * @param mixed[] $data |
||
177 | * |
||
178 | * @return GeocoderAddress[] |
||
179 | */ |
||
180 | private function buildAddresses(array $data) |
||
190 | |||
191 | /** |
||
192 | * @param mixed[] $data |
||
193 | * |
||
194 | * @return GeocoderAddress |
||
195 | */ |
||
196 | private function buildAddress(array $data) |
||
205 | |||
206 | /** |
||
207 | * @param mixed[] $data |
||
208 | * |
||
209 | * @return GeocoderGeometry |
||
210 | */ |
||
211 | private function buildGeometry(array $data) |
||
221 | |||
222 | /** |
||
223 | * @param mixed[] $data |
||
224 | * |
||
225 | * @return Bound |
||
226 | */ |
||
227 | private function buildBound(array $data) |
||
234 | |||
235 | /** |
||
236 | * @param mixed[] $data |
||
237 | * |
||
238 | * @return Coordinate |
||
239 | */ |
||
240 | private function buildCoordinate(array $data) |
||
244 | } |
||
245 |
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.