Conditions | 56 |
Paths | > 20000 |
Total Lines | 68 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
224 | public static function createFromXML(SimpleXMLElement $xml): self |
||
225 | { |
||
226 | if (!isset($xml->Record)) { |
||
227 | throw new BpostInvalidXmlResponseException('"Record" missing'); |
||
228 | } |
||
229 | |||
230 | $recordXml = $xml->Record; |
||
231 | $poi = new self(); |
||
232 | |||
233 | // Identifiants / type / nom |
||
234 | if (isset($recordXml->Id) && (string)$recordXml->Id !== '') { $poi->setId((string)$recordXml->Id); } |
||
235 | if (isset($recordXml->ID) && (string)$recordXml->ID !== '') { $poi->setId((string)$recordXml->ID); } |
||
236 | |||
237 | if (isset($recordXml->Type) && (string)$recordXml->Type !== '') { $poi->setType((string)$recordXml->Type); } |
||
238 | |||
239 | if (isset($recordXml->Name) && (string)$recordXml->Name !== '') { $poi->setOffice((string)$recordXml->Name); } |
||
240 | if (isset($recordXml->OFFICE) && (string)$recordXml->OFFICE !== '') { $poi->setOffice((string)$recordXml->OFFICE); } |
||
241 | |||
242 | // Adresse |
||
243 | if (isset($recordXml->Street) && (string)$recordXml->Street !== '') { $poi->setStreet((string)$recordXml->Street); } |
||
244 | if (isset($recordXml->STREET) && (string)$recordXml->STREET !== '') { $poi->setStreet((string)$recordXml->STREET); } |
||
245 | |||
246 | if (isset($recordXml->Number) && (string)$recordXml->Number !== '') { $poi->setNr((string)$recordXml->Number); } |
||
247 | if (isset($recordXml->NR) && (string)$recordXml->NR !== '') { $poi->setNr((string)$recordXml->NR); } |
||
248 | |||
249 | if (isset($recordXml->Zip) && (string)$recordXml->Zip !== '') { $poi->setZip((string)$recordXml->Zip); } |
||
250 | if (isset($recordXml->ZIP) && (string)$recordXml->ZIP !== '') { $poi->setZip((string)$recordXml->ZIP); } |
||
251 | |||
252 | if (isset($recordXml->City) && (string)$recordXml->City !== '') { $poi->setCity((string)$recordXml->City); } |
||
253 | if (isset($recordXml->CITY) && (string)$recordXml->CITY !== '') { $poi->setCity((string)$recordXml->CITY); } |
||
254 | |||
255 | // Coordonnées |
||
256 | if (isset($recordXml->X) && (string)$recordXml->X !== '') { $poi->setX((int)$recordXml->X); } |
||
257 | if (isset($recordXml->Y) && (string)$recordXml->Y !== '') { $poi->setY((int)$recordXml->Y); } |
||
258 | if (isset($recordXml->Longitude) && (string)$recordXml->Longitude !== '') { $poi->setLongitude((float)$recordXml->Longitude); } |
||
259 | if (isset($recordXml->Latitude) && (string)$recordXml->Latitude !== '') { $poi->setLatitude((float)$recordXml->Latitude); } |
||
260 | |||
261 | // Services |
||
262 | if (isset($recordXml->Services) && isset($recordXml->Services->Service)) { |
||
263 | foreach ($recordXml->Services->Service as $serviceXml) { |
||
264 | $poi->addService(Service::createFromXML($serviceXml)); |
||
265 | } |
||
266 | } |
||
267 | |||
268 | if (isset($recordXml->Hours)) { |
||
269 | $hours = $recordXml->Hours; |
||
270 | |||
271 | if (isset($hours->Monday)) { $poi->addHour(Day::DAY_INDEX_MONDAY, Day::createFromXML($hours->Monday)); } |
||
272 | if (isset($hours->Tuesday)) { $poi->addHour(Day::DAY_INDEX_TUESDAY, Day::createFromXML($hours->Tuesday)); } |
||
273 | if (isset($hours->Wednesday)) { $poi->addHour(Day::DAY_INDEX_WEDNESDAY, Day::createFromXML($hours->Wednesday)); } |
||
274 | if (isset($hours->Thursday)) { $poi->addHour(Day::DAY_INDEX_THURSDAY, Day::createFromXML($hours->Thursday)); } |
||
275 | if (isset($hours->Friday)) { $poi->addHour(Day::DAY_INDEX_FRIDAY, Day::createFromXML($hours->Friday)); } |
||
276 | if (isset($hours->Saturday)) { $poi->addHour(Day::DAY_INDEX_SATURDAY, Day::createFromXML($hours->Saturday)); } |
||
277 | if (isset($hours->Sunday)) { $poi->addHour(Day::DAY_INDEX_SUNDAY, Day::createFromXML($hours->Sunday)); } |
||
278 | } |
||
279 | |||
280 | if (isset($recordXml->ClosedFrom) && (string)$recordXml->ClosedFrom !== '') { $poi->setClosedFrom((string)$recordXml->ClosedFrom); } |
||
281 | if (isset($recordXml->ClosedTo) && (string)$recordXml->ClosedTo !== '') { $poi->setClosedTo((string)$recordXml->ClosedTo); } |
||
282 | |||
283 | // Note |
||
284 | if (isset($recordXml->NOTE) && (string)$recordXml->NOTE !== '') { $poi->setNote((string)$recordXml->NOTE); } |
||
285 | |||
286 | // Lien page |
||
287 | if (isset($xml->Page) && isset($xml->Page['ServiceRef']) && (string)$xml->Page['ServiceRef'] !== '') { |
||
288 | $poi->setPage((string)$xml->Page['ServiceRef']); |
||
289 | } |
||
290 | |||
291 | return $poi; |
||
292 | } |
||
293 | } |