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 AnalyticsConfigRepository extends EntityRepository |
||
15 | { |
||
16 | /** |
||
17 | * Get the first config from the database, creates a new entry if the config doesn't exist yet |
||
18 | * |
||
19 | * @return AnalyticsConfig $config |
||
20 | */ |
||
21 | public function findFirst($createNew = true) |
||
36 | |||
37 | /** |
||
38 | * Get the default overviews for a config |
||
39 | * |
||
40 | * @return AnalyticsConfig $config |
||
|
|||
41 | */ |
||
42 | public function findDefaultOverviews($config) |
||
52 | |||
53 | /** |
||
54 | * Create a new config |
||
55 | * |
||
56 | * @return AnalyticsConfig |
||
57 | */ |
||
58 | public function createConfig() |
||
70 | |||
71 | /** |
||
72 | * Flush a config |
||
73 | * |
||
74 | * @param int $id the config id |
||
75 | */ |
||
76 | public function flushConfig($id = false) |
||
100 | |||
101 | /** |
||
102 | * Update the timestamp when data is collected |
||
103 | * |
||
104 | * @param int id |
||
105 | */ |
||
106 | public function setUpdated($id = false) |
||
114 | |||
115 | /** |
||
116 | * saves the token |
||
117 | * |
||
118 | * @param string $token |
||
119 | */ |
||
120 | public function saveToken($token, $id = false) |
||
128 | |||
129 | /** |
||
130 | * saves the property id |
||
131 | * |
||
132 | * @param string $propertyId |
||
133 | */ |
||
134 | public function savePropertyId($propertyId, $id = false) |
||
142 | |||
143 | /** |
||
144 | * saves the account id |
||
145 | * |
||
146 | * @param string $accountId |
||
147 | */ |
||
148 | public function saveAccountId($accountId, $id = false) |
||
156 | |||
157 | /** |
||
158 | * saves the profile id |
||
159 | * |
||
160 | * @param string $profileId |
||
161 | */ |
||
162 | View Code Duplication | public function saveProfileId($profileId, $id = false) |
|
170 | |||
171 | /** |
||
172 | * saves the config name |
||
173 | * |
||
174 | * @param string $profileId |
||
175 | */ |
||
176 | View Code Duplication | public function saveConfigName($name, $id = false) |
|
184 | |||
185 | /** |
||
186 | * Resets the profile id |
||
187 | * |
||
188 | * @param int id |
||
189 | */ |
||
190 | View Code Duplication | public function resetProfileId($id = false) |
|
198 | |||
199 | /** |
||
200 | * Resets the account id, property id and profile id |
||
201 | * |
||
202 | * @param int id |
||
203 | */ |
||
204 | public function resetPropertyId($id = false) |
||
214 | } |
||
215 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.