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 array[Campaign] |
||
|
|||
37 | * @throws \Exception |
||
38 | */ |
||
39 | 1 | public function listAll($projectId, $page=0, $perPage=10) |
|
72 | |||
73 | /** |
||
74 | * Reads a campaign. |
||
75 | * @param integer $campaignId |
||
76 | * @return Campaign |
||
77 | * @throws \Exception |
||
78 | */ |
||
79 | 1 | View Code Duplication | public function get($campaignId) |
91 | |||
92 | /** |
||
93 | * Get campaign results |
||
94 | * @param integer $campaignId The id for the campaign you want results for |
||
95 | * @param string $starTime The earliest time to count events in results. Defaults to the time that the campaign was first activated. |
||
96 | * @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. |
||
97 | * @throws \Exception |
||
98 | */ |
||
99 | 1 | public function getResults($campaignId, $startTime = null, $endTime = null) |
|
120 | |||
121 | /** |
||
122 | * Create a new Campaign in your account |
||
123 | * @param Campaign $campaign |
||
124 | */ |
||
125 | 1 | public function create($campaign) |
|
138 | |||
139 | /** |
||
140 | * Update a Campaign |
||
141 | * @param integer $campaignId |
||
142 | * @param Campaign $campaign |
||
143 | * @throws \Exception |
||
144 | */ |
||
145 | 1 | public function update($campaignId, $campaign) |
|
158 | |||
159 | /** |
||
160 | * Delete Campaign by ID |
||
161 | * @param integer $campaignId |
||
162 | * @throws \Exception |
||
163 | */ |
||
164 | 1 | public function delete($campaignId) |
|
169 | } |
||
170 | |||
173 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.