| Conditions | 18 |
| Paths | 16 |
| Total Lines | 52 |
| 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 |
||
| 156 | public function Fetch($verbose = false) |
||
| 157 | { |
||
| 158 | $count = 0; |
||
| 159 | if ($this->FacebookPageID) { |
||
| 160 | $items = SilverstripeFacebookConnector::get_feed($this->FacebookPageID); |
||
| 161 | if ($items) { |
||
| 162 | foreach ($items as $item) { |
||
| 163 | $filter = array("UID" => $item["id"]); |
||
| 164 | if (! FacebookFeed_Item::get()->filter($filter)->first()) { |
||
| 165 | $count++; |
||
| 166 | $message = ""; |
||
| 167 | if (isset($item["message"])) { |
||
| 168 | $message = $item["message"]; |
||
| 169 | } elseif (isset($item["description"])) { |
||
| 170 | $message = $item["description"]; |
||
| 171 | } |
||
| 172 | //Converts UTF-8 into ISO-8859-1 to solve special symbols issues |
||
| 173 | $message = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $message); |
||
| 174 | $message = $this->stripUnsafe($message); |
||
| 175 | //Get status update time |
||
| 176 | $pubDate = strtotime(isset($item["created_time"]) ? $item["created_time"] : "today"); |
||
| 177 | $convertedDate = gmdate($timeFormat = 'Y-m-d', $pubDate); //Customize this to your liking |
||
| 178 | //Get link to update |
||
| 179 | //Store values in array |
||
| 180 | $obj = FacebookFeed_Item::create($filter); |
||
| 181 | $obj->Title = (string) (isset($item["name"]) ? $item["name"] : ""); |
||
| 182 | $obj->Date = $convertedDate; |
||
| 183 | $obj->Author = (string) (isset($item["from"]["name"]) ? $item["from"]["name"] : ""); |
||
| 184 | $obj->Link = (string) (isset($item["link"]) ? $item["link"] : ""); |
||
| 185 | $obj->PictureLink = (string) (isset($item["full_picture"]) ? $item["full_picture"] : ""); |
||
| 186 | $obj->Description = $message; |
||
| 187 | $obj->FacebookFeed_PageID = $this->ID; |
||
| 188 | $obj->write(); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } else { |
||
| 192 | if ($verbose) { |
||
| 193 | DB::alteration_message("ERROR: no data returned", "deleted"); |
||
| 194 | } |
||
| 195 | } |
||
| 196 | if ($count == 0 && $verbose) { |
||
| 197 | DB::alteration_message("Nothing to add."); |
||
| 198 | } |
||
| 199 | } else { |
||
| 200 | if ($verbose) { |
||
| 201 | DB::alteration_message("ERROR: no Facebook Page ID provided", "deleted"); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | if ($count && $verbose) { |
||
| 205 | DB::alteration_message("Added $count items", "created"); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 226 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.