| Conditions | 7 |
| Paths | 6 |
| Total Lines | 70 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | 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 |
||
| 113 | public function renderRss(array $data): void |
||
| 114 | { |
||
| 115 | if (empty($data)) { |
||
| 116 | return; |
||
| 117 | } |
||
| 118 | |||
| 119 | $data = json_decode(json_encode($data)); |
||
| 120 | |||
| 121 | // Items |
||
| 122 | foreach ($data as $item) { |
||
| 123 | |||
| 124 | $title = $this->strLimitChars($this->strClean($item->title), 150, ''); |
||
| 125 | $description = $this->strLimitChars($this->strClean($item->description), 5000, ''); |
||
| 126 | |||
| 127 | // item element |
||
| 128 | $itemElement = $this->xml->createElement("item"); |
||
| 129 | |||
| 130 | // title |
||
| 131 | $itemElement->appendChild($this->xml->createElement('title', $title)); |
||
| 132 | |||
| 133 | // description Element |
||
| 134 | $itemDescription = $this->xml->createElement('description'); |
||
| 135 | $itemDescription->appendChild($this->xml->createCDATASection($description)); |
||
| 136 | $itemElement->appendChild($itemDescription); |
||
| 137 | |||
| 138 | $dtPub = date('D, d M Y H:i:s O', strtotime($item->publication)); |
||
| 139 | $itemElement->appendChild($this->xml->createElement('pubDate', $dtPub)); |
||
| 140 | |||
| 141 | // enclosure |
||
| 142 | $itemEnclosure = $this->xml->createElement('enclosure'); |
||
| 143 | $itemEnclosure->setAttribute('url', $item->image->url); |
||
| 144 | $itemEnclosure->setAttribute('type', 'image/*'); |
||
| 145 | $itemEnclosure->setAttribute('length', 0); |
||
| 146 | $itemElement->appendChild($itemEnclosure); |
||
| 147 | |||
| 148 | // image |
||
| 149 | $itemImage = $this->xml->createElement('image'); |
||
| 150 | |||
| 151 | $imageTitle = $this->xml->createElement('title'); |
||
| 152 | $imageTitle->appendChild($this->xml->createCDATASection($item->image->title)); |
||
| 153 | |||
| 154 | $itemImage->appendChild($this->xml->createElement('link', $item->link)); |
||
| 155 | $itemImage->appendChild($this->xml->createElement('url', $item->image->url)); |
||
| 156 | $itemImage->appendChild($imageTitle); |
||
| 157 | |||
| 158 | $itemElement->appendChild($itemImage); |
||
| 159 | //image - end |
||
| 160 | |||
| 161 | // others |
||
| 162 | $itemElement->appendChild($this->xml->createElement('link', $item->link)); |
||
| 163 | $itemElement->appendChild($this->xml->createElement('guid', $item->link)); |
||
| 164 | |||
| 165 | |||
| 166 | //FB ADS PRODUCTS |
||
| 167 | if ($this->facebookAds && !empty($item->facebook_ads)) { |
||
| 168 | $this->setFacebookAds($itemElement, $item->facebook_ads); |
||
| 169 | } |
||
| 170 | |||
| 171 | // GOOGLE MERCHANT |
||
| 172 | if ($this->googleMerchant && !empty($item->google_merchant)) { |
||
| 173 | $this->setGoogleMerchant($itemElement, $item->google_merchant, $title, $description); |
||
| 174 | } |
||
| 175 | |||
| 176 | $this->channel->appendChild($itemElement); |
||
| 177 | } |
||
| 178 | |||
| 179 | $this->xml->appendChild($this->rss); |
||
| 180 | |||
| 181 | header('Content-type: text-xml'); |
||
| 182 | echo $this->xml->saveXML(); |
||
| 183 | } |
||
| 262 | } |