| Conditions | 16 |
| Paths | 7 |
| Total Lines | 66 |
| Code Lines | 36 |
| 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 |
||
| 85 | private function getRss($feeds, $toChannel) |
||
| 86 | { |
||
| 87 | foreach ($feeds as $rssUrl) { |
||
| 88 | //Check that url is set |
||
| 89 | if (empty($rssUrl) || is_null($rssUrl) || $rssUrl === 0 || $rssUrl === '0') { |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | |||
| 93 | $rss = new SimpleXMLElement($rssUrl, null, true); // XML parser |
||
| 94 | if ($rss===null || !is_object($rss)) { |
||
| 95 | $this->logger->addInfo("Failed to load xml file: {$rssUrl}"); |
||
| 96 | break; |
||
| 97 | } |
||
| 98 | if (!is_object($rss->feed)) { |
||
| 99 | $this->logger->addInfo("Feed is not an object at: {$rssUrl}"); |
||
| 100 | break; |
||
| 101 | } |
||
| 102 | $feedLink = $rss->feed->id; |
||
| 103 | $latestTopicDate = getPermCache("rssFeed{$feedLink}"); |
||
| 104 | |||
| 105 | //Check if feed has been checked before |
||
| 106 | if ($latestTopicDate === NULL) { |
||
| 107 | // Set date to now to avoid posting old articles |
||
| 108 | setPermCache("rssFeed{$feedLink}", time()); |
||
| 109 | continue; |
||
| 110 | } |
||
| 111 | |||
| 112 | //Find item to check if feed is formatted |
||
| 113 | $itemTitle = $rss->entry->title; |
||
| 114 | $itemUrl = $rss->entry->id; |
||
| 115 | $strDate = $rss->entry->published; |
||
| 116 | |||
| 117 | $itemDate = strtotime($strDate); |
||
| 118 | |||
| 119 | //Check to see if feed is formatted correctly |
||
| 120 | if (is_null($itemTitle) || is_null($itemUrl) || is_null($itemDate)) { |
||
| 121 | $this->logger->addInfo("rssReader: {$rssUrl} is not a properly formatted RSS feed. {$itemTitle} {$itemUrl} {$itemDate}"); |
||
| 122 | continue; |
||
| 123 | } |
||
| 124 | |||
| 125 | //Find item to post |
||
| 126 | foreach ($rss->entry as $item) { |
||
| 127 | //Get item details |
||
| 128 | $itemTitle = $item->title; |
||
| 129 | $itemUrl = $item->id; |
||
| 130 | $itemPubbed = $item->published; |
||
| 131 | $itemDate = strtotime($item->published); |
||
| 132 | |||
| 133 | //Check if item is old |
||
| 134 | if ($itemDate <= $latestTopicDate) { |
||
| 135 | continue; |
||
| 136 | } |
||
| 137 | |||
| 138 | //Set message |
||
| 139 | $msg = "\n**{$itemTitle}**\n\n*{$itemPubbed}*\n{$itemUrl}"; |
||
| 140 | |||
| 141 | //Send message |
||
| 142 | $channelID = $toChannel; |
||
| 143 | queueMessage($msg, $channelID, $this->guild); |
||
| 144 | $this->logger->addInfo("rssReader: Item Queued {$itemTitle}"); |
||
| 145 | if ($itemDate > getPermCache("rssFeed{$feedLink}")) { |
||
| 146 | setPermCache("rssFeed{$feedLink}", $itemDate); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.