| Conditions | 5 |
| Paths | 107 |
| Total Lines | 67 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 49 | public function parse($uri) |
||
| 50 | { |
||
| 51 | $cfp = clone($this->cfp); |
||
| 52 | try { |
||
| 53 | $dom = new \DOMDocument('1.0', 'UTF-8'); |
||
| 54 | |||
| 55 | $content = file_Get_contents($uri); |
||
| 56 | $content = mb_convert_encoding($content, 'UTF-8'); |
||
| 57 | $dom->loadHTML('<?xml version="1.0" charset="UTF-8" ?>' . $content); |
||
| 58 | $dom->preserveWhiteSpace = false; |
||
| 59 | |||
| 60 | $xpath = new \DOMXPath($dom); |
||
| 61 | |||
| 62 | $closingDateParser = new ClosingDate(); |
||
| 63 | $cfp->dateEnd = $closingDateParser->parse($dom, $xpath); |
||
| 64 | |||
| 65 | $eventPageDom = $this->getEventPage($xpath); |
||
| 66 | $eventXpath = new \DOMXPath(($eventPageDom)); |
||
| 67 | |||
| 68 | $descriptionParser = new Description(); |
||
| 69 | $cfp->description = $descriptionParser->parse($dom, $xpath); |
||
| 70 | |||
| 71 | $openingDateParser = new OpeningDate(); |
||
| 72 | $cfp->dateStart = $openingDateParser->parse($dom, $xpath); |
||
| 73 | |||
| 74 | $cfpUriParser = new Uri(); |
||
| 75 | $cfp->uri = $cfpUriParser->parse($dom, $xpath); |
||
| 76 | |||
| 77 | $confNameParser = new EventName(); |
||
| 78 | $cfp->conferenceName = $confNameParser->parse($dom, $xpath); |
||
| 79 | |||
| 80 | $confUriParser = new EventUri(); |
||
| 81 | $cfp->conferenceUri = $confUriParser->parse($eventPageDom, $eventXpath); |
||
| 82 | |||
| 83 | $eventStartDate = new EventStartDate(); |
||
| 84 | $cfp->eventStartDate = $eventStartDate->parse($dom, $xpath); |
||
| 85 | |||
| 86 | try { |
||
| 87 | $eventEndDate = new EventEndDate(); |
||
| 88 | $cfp->eventEndDate = $eventEndDate->parse($dom, $xpath); |
||
| 89 | } catch (\InvalidArgumentException $e) { |
||
| 90 | $cfp->eventEndDate = $cfp->eventStartDate; |
||
| 91 | } |
||
| 92 | |||
| 93 | $eventLocation = new Location(); |
||
| 94 | $cfp->location = $eventLocation->parse($dom, $xpath); |
||
| 95 | |||
| 96 | try { |
||
| 97 | $location = $this->getLatLonForLocation($cfp->location); |
||
| 98 | $cfp->latitude = $location[0]; |
||
|
|
|||
| 99 | $cfp->longitude = $location[1]; |
||
| 100 | } catch (\UnexpectedValueException $e) { |
||
| 101 | error_log($e->getMessage()); |
||
| 102 | } |
||
| 103 | |||
| 104 | try { |
||
| 105 | $tags = new Tags(); |
||
| 106 | $cfp->tags = $tags->parse($eventPageDom, $eventXpath); |
||
| 107 | } catch (\InvalidArgumentException $e) { |
||
| 108 | $cfp->tags = []; |
||
| 109 | } |
||
| 110 | |||
| 111 | return $cfp; |
||
| 112 | } catch (\Exception $e) { |
||
| 113 | throw $e; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 152 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.