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 AnalyticsConfigRepository extends EntityRepository |
||
16 | { |
||
17 | /** |
||
18 | * Get the first config from the database, creates a new entry if the config doesn't exist yet |
||
19 | * |
||
20 | * @return AnalyticsConfig $config |
||
21 | */ |
||
22 | public function findFirst($createNew = true) |
||
39 | |||
40 | /** |
||
41 | * Get the default overviews for a config |
||
42 | * |
||
43 | * @return AnalyticsConfig $config |
||
|
|||
44 | */ |
||
45 | public function findDefaultOverviews($config) |
||
55 | |||
56 | /** |
||
57 | * Create a new config |
||
58 | * |
||
59 | * @return AnalyticsConfig |
||
60 | */ |
||
61 | public function createConfig() |
||
73 | |||
74 | /** |
||
75 | * Flush a config |
||
76 | * |
||
77 | * @param int $id the config id |
||
78 | */ |
||
79 | public function flushConfig($id = false) |
||
103 | |||
104 | /** |
||
105 | * Update the timestamp when data is collected |
||
106 | * |
||
107 | * @param int id |
||
108 | */ |
||
109 | public function setUpdated($id = false) |
||
117 | |||
118 | /** |
||
119 | * saves the token |
||
120 | * |
||
121 | * @param string $token |
||
122 | */ |
||
123 | public function saveToken($token, $id = false) |
||
131 | |||
132 | /** |
||
133 | * saves the property id |
||
134 | * |
||
135 | * @param string $propertyId |
||
136 | */ |
||
137 | public function savePropertyId($propertyId, $id = false) |
||
145 | |||
146 | /** |
||
147 | * saves the account id |
||
148 | * |
||
149 | * @param string $accountId |
||
150 | */ |
||
151 | public function saveAccountId($accountId, $id = false) |
||
159 | |||
160 | /** |
||
161 | * saves the profile id |
||
162 | * |
||
163 | * @param string $profileId |
||
164 | */ |
||
165 | View Code Duplication | public function saveProfileId($profileId, $id = false) |
|
173 | |||
174 | /** |
||
175 | * saves the config name |
||
176 | * |
||
177 | * @param string $profileId |
||
178 | */ |
||
179 | View Code Duplication | public function saveConfigName($name, $id = false) |
|
187 | |||
188 | /** |
||
189 | * Resets the profile id |
||
190 | * |
||
191 | * @param int id |
||
192 | */ |
||
193 | View Code Duplication | public function resetProfileId($id = false) |
|
201 | |||
202 | /** |
||
203 | * Resets the account id, property id and profile id |
||
204 | * |
||
205 | * @param int id |
||
206 | */ |
||
207 | public function resetPropertyId($id = false) |
||
217 | } |
||
218 |
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.