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 |
||
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 | $descriptionParser = new Description(); |
||
63 | $cfp->description = $descriptionParser->parse($dom, $xpath); |
||
64 | |||
65 | $closingDateParser = new ClosingDate(); |
||
66 | $cfp->dateEnd = $closingDateParser->parse($dom, $xpath); |
||
67 | |||
68 | $cfpUriParser = new Uri(); |
||
69 | $cfp->uri = $cfpUriParser->parse($dom, $xpath); |
||
70 | |||
71 | $confNameParser = new EventName(); |
||
72 | $cfp->conferenceName = $confNameParser->parse($dom, $xpath); |
||
73 | |||
74 | $confUriParser = new EventUri(); |
||
75 | $cfp->conferenceUri = 'http://lanyrd.com/' . $confUriParser->parse($dom, $xpath); |
||
76 | |||
77 | $eventStartDate = new EventStartDate(); |
||
78 | $cfp->eventStartDate = $eventStartDate->parse($dom, $xpath); |
||
79 | |||
80 | try { |
||
81 | $eventEndDate = new EventEndDate(); |
||
82 | $cfp->eventEndDate = $eventEndDate->parse($dom, $xpath); |
||
83 | } catch (\InvalidArgumentException $e) { |
||
84 | $cfp->eventEndDate = $cfp->eventStartDate; |
||
85 | } |
||
86 | |||
87 | $eventLocation = new Location(); |
||
88 | $cfp->location = $eventLocation->parse($dom, $xpath); |
||
89 | |||
90 | try { |
||
91 | $location = $this->getLatLonForLocation($cfp->location); |
||
92 | $cfp->latitude = $location[0]; |
||
93 | $cfp->longitude = $location[1]; |
||
94 | } catch (\UnexpectedValueException $e) { |
||
95 | error_log($e->getMessage()); |
||
96 | } |
||
97 | |||
98 | try { |
||
99 | $tags = new Tags(); |
||
100 | $cfp->tags = $tags->parse($dom, $xpath); |
||
101 | } catch (\InvalidArgumentException $e) { |
||
102 | $cfp->tags = []; |
||
103 | } |
||
104 | |||
105 | return $cfp; |
||
106 | } catch (\Exception $e) { |
||
107 | throw $e; |
||
108 | } |
||
109 | } |
||
110 | |||
128 |