| Conditions | 16 |
| Paths | 16384 |
| Total Lines | 68 |
| 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 |
||
| 100 | private function renderItem(Item $item) |
||
| 101 | { |
||
| 102 | $result = [ |
||
| 103 | 'id' => $item->getId(), |
||
| 104 | ]; |
||
| 105 | |||
| 106 | if ($url = $item->getUrl()) { |
||
| 107 | $result['url'] = $url; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($externalUrl = $item->getExternalUrl()) { |
||
| 111 | $result['external_url'] = $externalUrl; |
||
| 112 | } |
||
| 113 | |||
| 114 | if ($title = $item->getTitle()) { |
||
| 115 | $result['title'] = $title; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($contentHtml = $item->getContentHtml()) { |
||
| 119 | $result['content_html'] = $contentHtml; |
||
| 120 | } |
||
| 121 | |||
| 122 | if ($contentText = $item->getContentText()) { |
||
| 123 | $result['content_text'] = $contentText; |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($summary = $item->getSummary()) { |
||
| 127 | $result['summary'] = $summary; |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($image = $item->getImage()) { |
||
| 131 | $result['image'] = $image; |
||
| 132 | } |
||
| 133 | |||
| 134 | if ($bannerImage = $item->getBannerImage()) { |
||
| 135 | $result['banner_image'] = $bannerImage; |
||
| 136 | } |
||
| 137 | |||
| 138 | if ($datePublished = $item->getDatePublished()) { |
||
| 139 | $result['date_published'] = $datePublished->format(DateTime::ATOM); |
||
| 140 | } |
||
| 141 | |||
| 142 | if ($dateModified = $item->getDateModified()) { |
||
| 143 | $result['date_modified'] = $dateModified->format(DateTime::ATOM); |
||
| 144 | } |
||
| 145 | |||
| 146 | if ($tags = $item->getTags()) { |
||
| 147 | $result['tags'] = $tags; |
||
| 148 | } |
||
| 149 | |||
| 150 | if ($attachments = $item->getAttachments()) { |
||
| 151 | $result['attachments'] = array_map(function(Attachment $attachment) { |
||
| 152 | return $this->renderAttachment($attachment); |
||
| 153 | }, $attachments); |
||
| 154 | } |
||
| 155 | |||
| 156 | if ($author = $item->getAuthor()) { |
||
| 157 | $result['author'] = $this->renderAuthor($author); |
||
| 158 | } |
||
| 159 | |||
| 160 | if ($extensions = $item->getExtensions()) { |
||
| 161 | foreach ($extensions as $key => $extension) { |
||
| 162 | $result['_'.$key] = $extension; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | return $result; |
||
| 167 | } |
||
| 168 | |||
| 236 |