Conditions | 10 |
Paths | 108 |
Total Lines | 44 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
171 | public function asXML() |
||
172 | { |
||
173 | $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item></item>', |
||
174 | LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL); |
||
175 | $xml->addChild('title', $this->title); |
||
176 | $xml->addChild('link', $this->url); |
||
177 | if ($this->pubDate !== null) { |
||
178 | $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate)); |
||
179 | } |
||
180 | |||
181 | if ($this->creator) { |
||
182 | $xml->addChildCData("xmlns:dc:creator", $this->creator); |
||
183 | } |
||
184 | if ($this->guid) { |
||
185 | $guid = $xml->addChild('guid', $this->guid); |
||
186 | |||
187 | if ($this->isPermalink) { |
||
188 | $guid->addAttribute('isPermaLink', 'true'); |
||
189 | } |
||
190 | } |
||
191 | |||
192 | foreach ($this->categories as $category) { |
||
193 | $element = $xml->addChild('category', $category[0]); |
||
194 | |||
195 | if (isset($category[1])) { |
||
196 | $element->addAttribute('domain', $category[1]); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | $xml->addChild('description', $this->description); |
||
201 | $xml->addChildCData('xmlns:content:encoded', $this->content); |
||
202 | |||
203 | if (is_array($this->enclosure) && (count($this->enclosure) == 3)) { |
||
204 | $element = $xml->addChild('enclosure'); |
||
205 | $element->addAttribute('url', $this->enclosure['url']); |
||
206 | $element->addAttribute('type', $this->enclosure['type']); |
||
207 | |||
208 | if ($this->enclosure['length']) { |
||
209 | $element->addAttribute('length', $this->enclosure['length']); |
||
210 | } |
||
211 | } |
||
212 | |||
213 | return $xml; |
||
214 | } |
||
215 | } |
||
216 |