Conditions | 5 |
Paths | 103 |
Total Lines | 61 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
50 | public function parse($uri) |
||
51 | { |
||
52 | $cfp = clone($this->cfp); |
||
53 | try { |
||
54 | $dom = new \DOMDocument('1.0', 'UTF-8'); |
||
55 | |||
56 | $content = file_Get_contents($uri); |
||
57 | $content = mb_convert_encoding($content, 'UTF-8'); |
||
58 | $dom->loadHTML('<?xml version="1.0" charset="UTF-8" ?>' . $content); |
||
59 | $dom->preserveWhiteSpace = false; |
||
60 | |||
61 | $xpath = new \DOMXPath($dom); |
||
62 | |||
63 | $descriptionParser = new Description(); |
||
64 | $cfp->description = $descriptionParser->parse($dom, $xpath); |
||
65 | |||
66 | $closingDateParser = new ClosingDate(); |
||
67 | $cfp->dateEnd = $closingDateParser->parse($dom, $xpath); |
||
68 | |||
69 | $cfpUriParser = new Uri(); |
||
70 | $cfp->uri = $cfpUriParser->parse($dom, $xpath); |
||
71 | |||
72 | $confNameParser = new EventName(); |
||
73 | $cfp->conferenceName = $confNameParser->parse($dom, $xpath); |
||
74 | |||
75 | $confUriParser = new EventUri(); |
||
76 | $cfp->conferenceUri = 'http://lanyrd.com/' . $confUriParser->parse($dom, $xpath); |
||
77 | |||
78 | $eventStartDate = new EventStartDate(); |
||
79 | $cfp->eventStartDate = $eventStartDate->parse($dom, $xpath); |
||
80 | |||
81 | try { |
||
82 | $eventEndDate = new EventEndDate(); |
||
83 | $cfp->eventEndDate = $eventEndDate->parse($dom, $xpath); |
||
84 | } catch (\InvalidArgumentException $e) { |
||
85 | $cfp->eventEndDate = $cfp->eventStartDate; |
||
86 | } |
||
87 | |||
88 | $eventLocation = new Location(); |
||
89 | $cfp->location = $eventLocation->parse($dom, $xpath); |
||
90 | |||
91 | try { |
||
92 | $location = $this->getLatLonForLocation($cfp->location); |
||
93 | $cfp->latitude = $location[0]; |
||
94 | $cfp->longitude = $location[1]; |
||
95 | } catch (\UnexpectedValueException $e) { |
||
96 | error_log($e->getMessage()); |
||
97 | } |
||
98 | |||
99 | try { |
||
100 | $tags = new Tags(); |
||
101 | $cfp->tags = $tags->parse($dom, $xpath); |
||
102 | } catch (\InvalidArgumentException $e) { |
||
103 | $cfp->tags = []; |
||
104 | } |
||
105 | |||
106 | return $cfp; |
||
107 | } catch (\Exception $e) { |
||
108 | throw $e; |
||
109 | } |
||
110 | } |
||
111 | |||
135 |