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 |
||
14 | class Audiences |
||
15 | { |
||
16 | /** |
||
17 | * Optimizely API Client. |
||
18 | * @var WebMarketingROI\OptimizelyPHP\OptimizelyApiClient |
||
19 | */ |
||
20 | private $client; |
||
21 | |||
22 | /** |
||
23 | * Constructor. |
||
24 | */ |
||
25 | 4 | public function __construct($client) |
|
29 | |||
30 | /** |
||
31 | * List Audiences for a Project |
||
32 | * @param integer $projectId |
||
33 | * @param integer $page |
||
34 | * @param integer $perPage |
||
35 | * @return Result |
||
36 | * @throws Exception |
||
37 | */ |
||
38 | 1 | public function listAll($projectId, $page=1, $perPage=25) |
|
66 | |||
67 | /** |
||
68 | * Get metadata for a single Audience. |
||
69 | * @param type $audienceId |
||
70 | * @return Result |
||
71 | * @throws Exception |
||
72 | */ |
||
73 | 1 | public function get($audienceId) |
|
87 | |||
88 | /** |
||
89 | * Create an Audience for a Project. |
||
90 | * @param Result |
||
91 | */ |
||
92 | 1 | View Code Duplication | public function create($audience) |
109 | |||
110 | /** |
||
111 | * Update an Audience for a Project |
||
112 | * @param integer $audienceId |
||
113 | * @param Result |
||
114 | * @throws Exception |
||
115 | */ |
||
116 | 1 | View Code Duplication | public function update($audienceId, $audience) |
133 | } |
||
134 | |||
139 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.