Conditions | 12 |
Paths | 2048 |
Total Lines | 57 |
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 |
||
36 | public function render(Feed $feed) |
||
37 | { |
||
38 | $result = [ |
||
39 | 'version' => Versions::VERSION_1, |
||
40 | 'title' => $feed->getTitle(), |
||
41 | ]; |
||
42 | |||
43 | if ($homepageUrl = $feed->getHomepageUrl()) { |
||
44 | $result['home_page_url'] = $homepageUrl; |
||
45 | } |
||
46 | |||
47 | if ($feedUrl = $feed->getFeedUrl()) { |
||
48 | $result['feed_url'] = $feedUrl; |
||
49 | } |
||
50 | |||
51 | if ($description = $feed->getDescription()) { |
||
52 | $result['description'] = $description; |
||
53 | } |
||
54 | |||
55 | if ($userComment = $feed->getUserComment()) { |
||
56 | $result['user_comment'] = $userComment; |
||
57 | } |
||
58 | |||
59 | if ($nextUrl = $feed->getNextUrl()) { |
||
60 | $result['next_url'] = $nextUrl; |
||
61 | } |
||
62 | |||
63 | if ($icon = $feed->getIcon()) { |
||
64 | $result['icon'] = $icon; |
||
65 | } |
||
66 | |||
67 | if ($favicon = $feed->getFavicon()) { |
||
68 | $result['favicon'] = $favicon; |
||
69 | } |
||
70 | |||
71 | if ($author = $feed->getAuthor()) { |
||
72 | $result['author'] = $this->renderAuthor($author); |
||
73 | } |
||
74 | |||
75 | if (null !== $expired = $feed->isExpired()) { |
||
76 | $result['expired'] = (bool) $expired; |
||
77 | } |
||
78 | |||
79 | if ($items = $feed->getItems()) { |
||
80 | $result['items'] = array_map(function(Item $item) { |
||
81 | return $this->renderItem($item); |
||
82 | }, $items); |
||
83 | } |
||
84 | |||
85 | if ($hubs = $feed->getHubs()) { |
||
86 | $result['hubs'] = array_map(function(Hub $hub) { |
||
87 | return $this->renderHub($hub); |
||
88 | }, $hubs); |
||
89 | } |
||
90 | |||
91 | return json_encode($result, $this->flags); |
||
92 | } |
||
93 | |||
236 |