| Conditions | 17 |
| Paths | 14 |
| Total Lines | 54 |
| Code Lines | 28 |
| 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 |
||
| 133 | public function add(Url $url) |
||
| 134 | { |
||
| 135 | if ($this->isSitemapIndexable() && $this->getCurrentSitemapIndex()->getUrlCount() >= $this->limit) { |
||
| 136 | $this->addSitemapIndex($this->createSitemapIndex()); |
||
| 137 | } |
||
| 138 | |||
| 139 | $loc = $url->getLoc(); |
||
| 140 | if (empty($loc)) { |
||
| 141 | throw new \InvalidArgumentException('The url MUST have a loc attribute'); |
||
| 142 | } |
||
| 143 | |||
| 144 | if ($this->baseHost !== null) { |
||
| 145 | if ($this->needHost($loc)) { |
||
| 146 | $url->setLoc($this->baseHost.$loc); |
||
| 147 | } |
||
| 148 | |||
| 149 | foreach ($url->getVideos() as $video) { |
||
| 150 | if ($this->needHost($video->getThumbnailLoc())) { |
||
| 151 | $video->setThumbnailLoc($this->baseHost.$video->getThumbnailLoc()); |
||
| 152 | } |
||
| 153 | |||
| 154 | if ($this->needHost($video->getContentLoc())) { |
||
| 155 | $video->setContentLoc($this->baseHost.$video->getContentLoc()); |
||
| 156 | } |
||
| 157 | |||
| 158 | $player = $video->getPlayerLoc(); |
||
| 159 | if ($player !== null && $this->needHost($player['loc'])) { |
||
| 160 | $video->setPlayerLoc($this->baseHost.$player['loc'], $player['allow_embed'], $player['autoplay']); |
||
| 161 | } |
||
| 162 | |||
| 163 | $gallery = $video->getGalleryLoc(); |
||
| 164 | if ($gallery !== null && $this->needHost($gallery['loc'])) { |
||
| 165 | $video->setGalleryLoc($this->baseHost.$gallery['loc'], $gallery['title']); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | foreach ($url->getImages() as $image) { |
||
| 170 | if ($this->needHost($image->getLoc())) { |
||
| 171 | $image->setLoc($this->baseHost.$image->getLoc()); |
||
| 172 | } |
||
| 173 | |||
| 174 | if ($this->needHost($image->getLicense())) { |
||
| 175 | $image->setLicense($this->baseHost.$image->getLicense()); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | $this->dumper->dump($this->formatter->formatUrl($url)); |
||
| 181 | |||
| 182 | if ($this->isSitemapIndexable()) { |
||
| 183 | $this->getCurrentSitemapIndex()->incrementUrl(); |
||
| 184 | } |
||
| 185 | |||
| 186 | return $this; |
||
| 187 | } |
||
| 203 |