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 |
||
24 | class Orgs extends AbstractPackage |
||
25 | { |
||
26 | /** |
||
27 | * List user organizations. |
||
28 | * |
||
29 | * If a user name is given, public and private organizations for the authenticated user will be listed. |
||
30 | * |
||
31 | * @param string $user The user name. |
||
32 | * |
||
33 | * @return object |
||
34 | * |
||
35 | * @since 1.0 |
||
36 | */ |
||
37 | View Code Duplication | public function getList($user = '') |
|
49 | |||
50 | /** |
||
51 | * Get an organization. |
||
52 | * |
||
53 | * @param string $org The organization name. |
||
54 | * |
||
55 | * @return object |
||
56 | * |
||
57 | * @since 1.0 |
||
58 | */ |
||
59 | public function get($org) |
||
69 | |||
70 | /** |
||
71 | * Edit an organization. |
||
72 | * |
||
73 | * @param string $org The organization name. |
||
74 | * @param string $billingEmail Billing email address. This address is not publicized. |
||
75 | * @param string $company The company name. |
||
76 | * @param string $email The email address. |
||
77 | * @param string $location The location name. |
||
78 | * @param string $name The name. |
||
79 | * |
||
80 | * @return object |
||
81 | * |
||
82 | * @since 1.0 |
||
83 | */ |
||
84 | public function edit($org, $billingEmail = '', $company = '', $email = '', $location = '', $name = '') |
||
108 | } |
||
109 |
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.