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 |
||
25 | class Profile extends FrontAppController |
||
26 | { |
||
27 | const BLOCK_PER_PAGE = 10; |
||
28 | const EVENT_CHANGE_PASSWORD = 'profile.changepassword.success'; |
||
29 | |||
30 | /** |
||
31 | * Fatty action like actionIndex(), actionShow() are located in standalone traits. |
||
32 | * This feature allow provide better read&write accessibility |
||
33 | */ |
||
34 | |||
35 | use Profile\ActionIndex { |
||
36 | index as actionIndex; |
||
37 | } |
||
38 | |||
39 | use Profile\ActionShow { |
||
40 | show as actionShow; |
||
41 | } |
||
42 | |||
43 | use Profile\ActionFeed { |
||
44 | feed as actionFeed; |
||
45 | } |
||
46 | |||
47 | use Profile\ActionWallDelete { |
||
48 | wallDelete as actionWalldelete; |
||
49 | } |
||
50 | |||
51 | use Profile\ActionAvatar { |
||
52 | avatar as actionAvatar; |
||
53 | } |
||
54 | |||
55 | use Profile\ActionNotifications { |
||
56 | notifications as actionNotifications; |
||
57 | } |
||
58 | |||
59 | use Profile\ActionIgnore { |
||
60 | ignore as actionIgnore; |
||
61 | } |
||
62 | |||
63 | use Profile\ActionSearch { |
||
64 | search as actionSearch; |
||
65 | } |
||
66 | |||
67 | |||
68 | /** |
||
69 | * Show user messages (based on ajax, all in template) |
||
70 | * @return string |
||
71 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
72 | * @throws ForbiddenException |
||
73 | */ |
||
74 | public function actionMessages() |
||
82 | |||
83 | /** |
||
84 | * User profile settings |
||
85 | * @return string |
||
86 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
87 | * @throws ForbiddenException |
||
88 | */ |
||
89 | public function actionSettings() |
||
112 | |||
113 | /** |
||
114 | * Action change user password |
||
115 | * @return string |
||
116 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
117 | * @throws ForbiddenException |
||
118 | */ |
||
119 | public function actionPassword() |
||
145 | |||
146 | /** |
||
147 | * Show user logs |
||
148 | * @return string |
||
149 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
150 | * @throws ForbiddenException |
||
151 | */ |
||
152 | public function actionLog() |
||
170 | |||
171 | /** |
||
172 | * Unblock always blocked user |
||
173 | * @param string $targetId |
||
174 | * @return string |
||
175 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
176 | * @throws ForbiddenException |
||
177 | * @throws NotFoundException |
||
178 | * @throws \Exception |
||
179 | */ |
||
180 | public function actionUnblock($targetId) |
||
209 | |||
210 | /** |
||
211 | * Cron schedule - build user profiles sitemap |
||
212 | */ |
||
213 | public static function buildSitemapSchedule() |
||
237 | |||
238 | /** |
||
239 | * Cleanup tables as scheduled action |
||
240 | */ |
||
241 | public static function cleanupTablesSchedule() |
||
250 | } |
||
251 |
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.