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 |
||
| 10 | class PodcastScraper |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var VendorInterface |
||
| 14 | */ |
||
| 15 | private $vendor; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param VendorInterface $vendor |
||
| 19 | */ |
||
| 20 | public function __construct(VendorInterface $vendor) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $value |
||
| 27 | * @return array |
||
| 28 | */ |
||
| 29 | View Code Duplication | public function get($value) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * @param Request $request |
||
| 48 | * @param string $value |
||
| 49 | * @return array |
||
| 50 | * @throws Exception |
||
| 51 | */ |
||
| 52 | View Code Duplication | private function search(Request $request, $value) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * @param string $feedUrl |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function find($feedUrl) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * @param int $limit |
||
| 88 | * @return PodcastScraper |
||
| 89 | */ |
||
| 90 | public function limit($limit) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return PodcastScraper |
||
| 100 | */ |
||
| 101 | public function original() |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param Request $request |
||
| 110 | * @param string $feedUrl |
||
| 111 | * @return array |
||
| 112 | * @throws Exception |
||
| 113 | */ |
||
| 114 | View Code Duplication | private function read(Request $request, $feedUrl) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * @param string $feedUrl |
||
| 130 | * |
||
| 131 | * @return mixed |
||
| 132 | */ |
||
| 133 | protected function getFeedFromUrl($feedUrl) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $message |
||
| 150 | * |
||
| 151 | * @return array |
||
| 152 | */ |
||
| 153 | protected function failedResponse($message) |
||
| 160 | } |
||
| 161 |