Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 21 | class RssParser extends Parser |
||
| 22 | { |
||
| 23 | protected $mandatoryFields = array( |
||
| 24 | 'channel', |
||
| 25 | ); |
||
| 26 | |||
| 27 | /** |
||
| 28 | * |
||
| 29 | * @deprecated removed in version 3.0 |
||
| 30 | */ |
||
| 31 | 3 | public function __construct() |
|
| 35 | |||
| 36 | /** |
||
| 37 | * @param SimpleXMLElement $xmlBody |
||
| 38 | * |
||
| 39 | * @return bool |
||
| 40 | * @deprecated removed in version 3.0 |
||
| 41 | */ |
||
| 42 | 3 | public function canHandle(SimpleXMLElement $xmlBody) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @param SimpleXMLElement $xmlBody |
||
| 49 | * @param FeedInterface $feed |
||
| 50 | * @param array $filters |
||
| 51 | * |
||
| 52 | * @return FeedInterface |
||
| 53 | */ |
||
| 54 | 6 | protected function parseBody(SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * @param SimpleXMLElement $xmlBody |
||
| 106 | * @param FeedInterface $feed |
||
| 107 | * @param $latestItemDate |
||
| 108 | */ |
||
| 109 | 1 | protected function detectAndSetLastModified(SimpleXMLElement $xmlBody, FeedInterface $feed, $latestItemDate) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * @param FeedInterface $feed |
||
| 122 | * @param string $rssDate |
||
| 123 | */ |
||
| 124 | 2 | protected function setLastModified(FeedInterface $feed, $rssDate) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Handles enclosures if any. |
||
| 133 | * |
||
| 134 | * @param SimpleXMLElement $element |
||
| 135 | * @param ItemInInterface $item |
||
| 136 | * |
||
| 137 | * @return $this |
||
| 138 | */ |
||
| 139 | 1 | protected function handleEnclosure(SimpleXMLElement $element, ItemInInterface $item) |
|
| 150 | |||
| 151 | /** |
||
| 152 | * According to RSS specs, either we can have a summary in description ; |
||
| 153 | * full content in description ; or a summary in description AND full content in content:encoded |
||
| 154 | * |
||
| 155 | * @param SimpleXMLElement $xmlElement |
||
| 156 | * @param ItemInInterface $item |
||
| 157 | */ |
||
| 158 | 1 | protected function handleDescription(SimpleXMLElement $xmlElement, ItemInInterface $item) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * Parse elements from Yahoo RSS Media extension |
||
| 172 | * |
||
| 173 | * @param SimpleXMLElement $xmlElement |
||
| 174 | * @param ItemInInterface $item with Media added |
||
| 175 | */ |
||
| 176 | 1 | protected function handleMediaExtension(SimpleXMLElement $xmlElement, ItemInInterface $item) |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Parse category elements. |
||
| 191 | * We may have more than one. |
||
| 192 | * |
||
| 193 | * @param SimpleXMLElement $element |
||
| 194 | * @param ItemInInterface $item |
||
| 195 | */ |
||
| 196 | 1 | View Code Duplication | protected function parseCategories(SimpleXMLElement $element, ItemInInterface $item) |
| 205 | |||
| 206 | /** |
||
| 207 | * Parse author: |
||
| 208 | * first we look at optional dc:creator, which is the author name |
||
| 209 | * if no, we fallback to the RSS author element which is the author email |
||
| 210 | * |
||
| 211 | * @param SimpleXMLElement $element |
||
| 212 | * @param ItemInInterface $item |
||
| 213 | */ |
||
| 214 | 1 | protected function handleAuthor(SimpleXMLElement $element, ItemInInterface $item) |
|
| 224 | } |
||
| 225 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.