| Conditions | 17 |
| Paths | 20 |
| Total Lines | 40 |
| Code Lines | 19 |
| Lines | 24 |
| Ratio | 60 % |
| Changes | 2 | ||
| 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 defined('SYSPATH') or die('No direct access allowed.'); |
||
| 75 | public static function create($info, $items, $format = 'rss2', $encoding = 'UTF-8') |
||
| 76 | { |
||
| 77 | $info += array('title' => 'Generated Feed', 'link' => '', 'generator' => 'KohanaPHP'); |
||
| 78 | |||
| 79 | $feed = '<?xml version="1.0" encoding="'.$encoding.'"?><rss version="2.0"><channel></channel></rss>'; |
||
| 80 | $feed = simplexml_load_string($feed); |
||
| 81 | |||
| 82 | View Code Duplication | foreach ($info as $name => $value) { |
|
| 83 | if (($name === 'pubDate' or $name === 'lastBuildDate') and (is_int($value) or ctype_digit($value))) { |
||
| 84 | // Convert timestamps to RFC 822 formatted dates |
||
| 85 | $value = date(DATE_RFC822, $value); |
||
| 86 | } elseif (($name === 'link' or $name === 'docs') and strpos($value, '://') === false) { |
||
| 87 | // Convert URIs to URLs |
||
| 88 | $value = url::site($value, 'http'); |
||
| 89 | } |
||
| 90 | |||
| 91 | // Add the info to the channel |
||
| 92 | $feed->channel->addChild($name, $value); |
||
| 93 | } |
||
| 94 | |||
| 95 | foreach ($items as $item) { |
||
| 96 | // Add the item to the channel |
||
| 97 | $row = $feed->channel->addChild('item'); |
||
| 98 | |||
| 99 | View Code Duplication | foreach ($item as $name => $value) { |
|
| 100 | if ($name === 'pubDate' and (is_int($value) or ctype_digit($value))) { |
||
| 101 | // Convert timestamps to RFC 822 formatted dates |
||
| 102 | $value = date(DATE_RFC822, $value); |
||
| 103 | } elseif (($name === 'link' or $name === 'guid') and strpos($value, '://') === false) { |
||
| 104 | // Convert URIs to URLs |
||
| 105 | $value = url::site($value, 'http'); |
||
| 106 | } |
||
| 107 | |||
| 108 | // Add the info to the row |
||
| 109 | $row->addChild($name, $value); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return $feed->asXML(); |
||
| 114 | } |
||
| 115 | } // End feed |
||
| 116 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.