| Conditions | 17 |
| Paths | 12 |
| 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 |
||
| 83 | public function add(Url $url) |
||
| 84 | { |
||
| 85 | if ($this->isSitemapIndexable() && $this->getCurrentSitemapIndex()->getUrlCount() >= $this->limit) { |
||
| 86 | $this->addSitemapIndex($this->createSitemapIndex()); |
||
| 87 | } |
||
| 88 | |||
| 89 | $loc = $url->getLoc(); |
||
| 90 | if (empty($loc)) { |
||
| 91 | throw new \InvalidArgumentException('The url MUST have a loc attribute'); |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($this->baseHost !== null) { |
||
| 95 | if ($this->needHost($loc)) { |
||
| 96 | $url->setLoc($this->baseHost.$loc); |
||
| 97 | } |
||
| 98 | |||
| 99 | foreach ($url->getVideos() as $video) { |
||
| 100 | if ($this->needHost($video->getThumbnailLoc())) { |
||
| 101 | $video->setThumbnailLoc($this->baseHost.$video->getThumbnailLoc()); |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($this->needHost($video->getContentLoc())) { |
||
| 105 | $video->setContentLoc($this->baseHost.$video->getContentLoc()); |
||
| 106 | } |
||
| 107 | |||
| 108 | $player = $video->getPlayerLoc(); |
||
| 109 | if ($player !== null && $this->needHost($player['loc'])) { |
||
| 110 | $video->setPlayerLoc($this->baseHost.$player['loc'], $player['allow_embed'], $player['autoplay']); |
||
| 111 | } |
||
| 112 | |||
| 113 | $gallery = $video->getGalleryLoc(); |
||
| 114 | if ($gallery !== null && $this->needHost($gallery['loc'])) { |
||
| 115 | $video->setGalleryLoc($this->baseHost.$gallery['loc'], $gallery['title']); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | foreach ($url->getImages() as $image) { |
||
| 120 | if ($this->needHost($image->getLoc())) { |
||
| 121 | $image->setLoc($this->baseHost.$image->getLoc()); |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($this->needHost($image->getLicense())) { |
||
| 125 | $image->setLicense($this->baseHost.$image->getLicense()); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | $this->dumper->dump($this->formatter->formatUrl($url)); |
||
| 131 | |||
| 132 | if ($this->isSitemapIndexable()) { |
||
| 133 | $this->getCurrentSitemapIndex()->incrementUrl(); |
||
| 134 | } |
||
| 135 | |||
| 136 | return $this; |
||
| 137 | } |
||
| 200 | } |