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 |
||
| 15 | class Campaigns |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Optimizely API Client. |
||
| 19 | * @var WebMarketingROI\OptimizelyPHP\OptimizelyApiClient |
||
| 20 | */ |
||
| 21 | private $client; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Constructor. |
||
| 25 | */ |
||
| 26 | 6 | public function __construct($client) |
|
| 30 | |||
| 31 | /** |
||
| 32 | * Returns the list of campaigns. |
||
| 33 | * @param integer $projectId |
||
| 34 | * @param integer $page |
||
| 35 | * @param integer $perPage |
||
| 36 | * @return Result |
||
| 37 | * @throws Exception |
||
| 38 | */ |
||
| 39 | 1 | public function listAll($projectId, $page=1, $perPage=25) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * Reads a campaign. |
||
| 76 | * @param integer $campaignId |
||
| 77 | * @return Result |
||
| 78 | * @throws Exception |
||
| 79 | */ |
||
| 80 | 1 | public function get($campaignId) |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Get campaign results |
||
| 96 | * @param integer $campaignId The id for the campaign you want results for |
||
| 97 | * @param string $starTime The earliest time to count events in results. Defaults to the time that the campaign was first activated. |
||
|
|
|||
| 98 | * @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. |
||
| 99 | * @return Result |
||
| 100 | * @throws Exception |
||
| 101 | */ |
||
| 102 | 1 | public function getResults($campaignId, $startTime = null, $endTime = null) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Create a new Campaign in your account |
||
| 129 | * @param Campaign $campaign |
||
| 130 | * @return Result |
||
| 131 | * @throws Exception |
||
| 132 | */ |
||
| 133 | 1 | View Code Duplication | public function create($campaign) |
| 150 | |||
| 151 | /** |
||
| 152 | * Update a Campaign |
||
| 153 | * @param integer $campaignId |
||
| 154 | * @param Campaign $campaign |
||
| 155 | * @return Result |
||
| 156 | * @throws Exception |
||
| 157 | */ |
||
| 158 | 1 | View Code Duplication | public function update($campaignId, $campaign) |
| 175 | |||
| 176 | /** |
||
| 177 | * Delete Campaign by ID |
||
| 178 | * @param integer $campaignId |
||
| 179 | * @return Result |
||
| 180 | * @throws Exception |
||
| 181 | */ |
||
| 182 | 1 | public function delete($campaignId) |
|
| 189 | } |
||
| 190 | |||
| 193 |
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.