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 Campaigns |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Optimizely API Client. |
||
| 20 | * @var WebMarketingROI\OptimizelyPHP\OptimizelyApiClient |
||
| 21 | */ |
||
| 22 | private $client; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Constructor. |
||
| 26 | */ |
||
| 27 | 8 | public function __construct($client) |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Returns the list of campaigns. |
||
| 34 | * @param integer $projectId |
||
| 35 | * @param integer $page |
||
| 36 | * @param integer $perPage |
||
| 37 | * @return Result |
||
| 38 | * @throws Exception |
||
| 39 | */ |
||
| 40 | 3 | public function listAll($projectId, $page=1, $perPage=25) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Reads a campaign. |
||
| 73 | * @param integer $campaignId |
||
| 74 | * @return Result |
||
| 75 | * @throws Exception |
||
| 76 | */ |
||
| 77 | 1 | public function get($campaignId) |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Get campaign results |
||
| 93 | * @param integer $campaignId The id for the campaign you want results for |
||
| 94 | * @param string $starTime The earliest time to count events in results. Defaults to the time that the campaign was first activated. |
||
|
|
|||
| 95 | * @param string $endTime The latest time to count events in results. Defaults to the time the campaign was last active or the current time if the campaign is still running. |
||
| 96 | * @return Result |
||
| 97 | * @throws Exception |
||
| 98 | */ |
||
| 99 | 1 | public function getResults($campaignId, $startTime = null, $endTime = null) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Create a new Campaign in your account |
||
| 126 | * @param Campaign $campaign |
||
| 127 | * @return Result |
||
| 128 | * @throws Exception |
||
| 129 | */ |
||
| 130 | 1 | View Code Duplication | public function create($campaign) |
| 147 | |||
| 148 | /** |
||
| 149 | * Update a Campaign |
||
| 150 | * @param integer $campaignId |
||
| 151 | * @param Campaign $campaign |
||
| 152 | * @return Result |
||
| 153 | * @throws Exception |
||
| 154 | */ |
||
| 155 | 1 | View Code Duplication | public function update($campaignId, $campaign) |
| 172 | |||
| 173 | /** |
||
| 174 | * Delete Campaign by ID |
||
| 175 | * @param integer $campaignId |
||
| 176 | * @return Result |
||
| 177 | * @throws Exception |
||
| 178 | */ |
||
| 179 | 1 | public function delete($campaignId) |
|
| 186 | } |
||
| 187 | |||
| 190 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.