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 |
||
| 16 | class SearchResultAdCrawler extends CrawlerAbstract |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @param $url |
||
| 20 | * @return SearchResultUrlParser |
||
| 21 | */ |
||
| 22 | 10 | protected function setUrlParser($url) |
|
| 26 | |||
| 27 | /** |
||
| 28 | * Return the Ad's ID |
||
| 29 | * |
||
| 30 | * @return string |
||
| 31 | */ |
||
| 32 | 10 | public function getId() |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Return the title |
||
| 39 | * |
||
| 40 | * @return mixed |
||
| 41 | */ |
||
| 42 | 10 | public function getTitle() |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Return the price |
||
| 49 | * |
||
| 50 | * @return int |
||
| 51 | */ |
||
| 52 | 10 | public function getPrice() |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Return the Ad's URL |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | 10 | public function getUrl() |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Return the data and time the ad was created |
||
| 74 | * |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | 10 | public function getCreatedAt() |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Return the thumb picture url |
||
| 96 | * |
||
| 97 | * @return null|string |
||
| 98 | */ |
||
| 99 | 10 | public function getThumb() |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Return the number of picture of the ad |
||
| 117 | * |
||
| 118 | * @return int |
||
| 119 | */ |
||
| 120 | 10 | public function getNbImage() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @return mixed |
||
| 131 | */ |
||
| 132 | 10 | View Code Duplication | public function getPlacement() |
| 140 | |||
| 141 | /** |
||
| 142 | * @return mixed |
||
| 143 | */ |
||
| 144 | 10 | View Code Duplication | public function getType() |
| 156 | |||
| 157 | /** |
||
| 158 | * @return object |
||
| 159 | */ |
||
| 160 | 10 | public function getAll() |
|
| 174 | |||
| 175 | /** |
||
| 176 | * Return the field's value |
||
| 177 | * |
||
| 178 | * @param $node |
||
| 179 | * @param $defaultValue |
||
| 180 | * @param $callback |
||
| 181 | * @param string $funcName |
||
| 182 | * @param string $funcParam |
||
| 183 | * |
||
| 184 | * @return mixed |
||
| 185 | */ |
||
| 186 | 10 | private function getFieldValue( |
|
| 199 | } |
||
| 200 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: