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 Users extends AbstractPackage |
||
25 | { |
||
26 | /** |
||
27 | * Get a single user. |
||
28 | * |
||
29 | * @param string $user The users login name. |
||
30 | * |
||
31 | * @return object |
||
32 | * |
||
33 | * @since 1.0 |
||
34 | * @throws \DomainException |
||
35 | */ |
||
36 | public function get($user) |
||
46 | |||
47 | /** |
||
48 | * Get the authenticated user. |
||
49 | * |
||
50 | * @return mixed |
||
51 | * |
||
52 | * @since 1.0 |
||
53 | * @throws \DomainException |
||
54 | */ |
||
55 | public function getAuthenticatedUser() |
||
65 | |||
66 | /** |
||
67 | * Update the authenticated user. |
||
68 | * |
||
69 | * @param string $name The full name |
||
70 | * @param string $email The email |
||
71 | * @param string $blog The blog |
||
72 | * @param string $company The company |
||
73 | * @param string $location The location |
||
74 | * @param string $hireable If he is unemployed :P |
||
75 | * @param string $bio The biometrical DNA fingerprint (or smthng...) |
||
76 | * |
||
77 | * @return mixed |
||
78 | * |
||
79 | * @since 1.0 |
||
80 | * @throws \DomainException |
||
81 | */ |
||
82 | public function edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '') |
||
102 | |||
103 | /** |
||
104 | * Get all users. |
||
105 | * |
||
106 | * This provides a dump of every user, in the order that they signed up for GitHub. |
||
107 | * |
||
108 | * @param integer $since The integer ID of the last User that you’ve seen. |
||
109 | * |
||
110 | * @return object |
||
111 | * |
||
112 | * @since 1.0 |
||
113 | * @throws \DomainException |
||
114 | */ |
||
115 | View Code Duplication | public function getList($since = 0) |
|
127 | } |
||
128 |
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.