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) { |
||
35 | |||
36 | /** |
||
37 | * Get the default overviews for a config |
||
38 | * |
||
39 | * @return AnalyticsConfig $config |
||
|
|||
40 | */ |
||
41 | public function findDefaultOverviews($config) { |
||
49 | |||
50 | /** |
||
51 | * Create a new config |
||
52 | * |
||
53 | * @return AnalyticsConfig |
||
54 | */ |
||
55 | public function createConfig() { |
||
65 | |||
66 | /** |
||
67 | * Flush a config |
||
68 | * |
||
69 | * @param int $id the config id |
||
70 | */ |
||
71 | public function flushConfig($id=false) { |
||
93 | |||
94 | /** |
||
95 | * Update the timestamp when data is collected |
||
96 | * |
||
97 | * @param int id |
||
98 | */ |
||
99 | public function setUpdated($id=false) { |
||
106 | |||
107 | /** |
||
108 | * saves the token |
||
109 | * |
||
110 | * @param string $token |
||
111 | */ |
||
112 | public function saveToken($token, $id=false) { |
||
119 | |||
120 | /** |
||
121 | * saves the property id |
||
122 | * |
||
123 | * @param string $propertyId |
||
124 | */ |
||
125 | public function savePropertyId($propertyId, $id=false) { |
||
132 | |||
133 | /** |
||
134 | * saves the account id |
||
135 | * |
||
136 | * @param string $accountId |
||
137 | */ |
||
138 | public function saveAccountId($accountId, $id=false) { |
||
145 | |||
146 | /** |
||
147 | * saves the profile id |
||
148 | * |
||
149 | * @param string $profileId |
||
150 | */ |
||
151 | View Code Duplication | public function saveProfileId($profileId, $id=false) { |
|
158 | |||
159 | /** |
||
160 | * saves the config name |
||
161 | * |
||
162 | * @param string $profileId |
||
163 | */ |
||
164 | View Code Duplication | public function saveConfigName($name, $id=false) { |
|
171 | |||
172 | /** |
||
173 | * Resets the profile id |
||
174 | * |
||
175 | * @param int id |
||
176 | */ |
||
177 | View Code Duplication | public function resetProfileId($id=false) { |
|
184 | |||
185 | /** |
||
186 | * Resets the account id, property id and profile id |
||
187 | * |
||
188 | * @param int id |
||
189 | */ |
||
190 | public function resetPropertyId($id=false) { |
||
199 | } |
||
200 |
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.