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 |
||
| 10 | class Statistics implements EventListenerInterface |
||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * ImplementedEvents method. |
||
| 15 | * |
||
| 16 | * @return array |
||
| 17 | */ |
||
| 18 | public function implementedEvents() |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Count the articles and write it in the Cache. |
||
| 31 | * |
||
| 32 | * @param \Cake\Event\Event $event The event that was fired. |
||
| 33 | * |
||
| 34 | * @return array|false |
||
| 35 | */ |
||
| 36 | View Code Duplication | public function newArticleStats(Event $event) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Count the article's comments and write it in the Cache. |
||
| 52 | * |
||
| 53 | * @param \Cake\Event\Event $event The event that was fired. |
||
| 54 | * |
||
| 55 | * @return array|false |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function newArticleCommentStats(Event $event) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Count the article's likes and write it in the Cache. |
||
| 73 | * |
||
| 74 | * @param \Cake\Event\Event $event The event that was fired. |
||
| 75 | * |
||
| 76 | * @return array|false |
||
| 77 | */ |
||
| 78 | View Code Duplication | public function newArticleLikeStats(Event $event) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Re-count the number of user and find the latest user and write it in the Cache. |
||
| 94 | * |
||
| 95 | * @param \Cake\Event\Event $event The event that was fired. |
||
| 96 | * |
||
| 97 | * @return array|false |
||
| 98 | */ |
||
| 99 | public function newUserStats(Event $event) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Get the Groups and write it in the Cache. |
||
| 121 | * |
||
| 122 | * @param \Cake\Event\Event $event The event that was fired. |
||
| 123 | * |
||
| 124 | * @return array|false |
||
| 125 | */ |
||
| 126 | public function updateGroupStats(Event $event) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Write the data into the Cache with the passed key. |
||
| 141 | * |
||
| 142 | * @param int|object|string $data The data to save in the Cache. |
||
| 143 | * @param string $key The key to save the data. |
||
| 144 | * |
||
| 145 | * @return bool |
||
| 146 | */ |
||
| 147 | protected function _writeCache($data, $key) |
||
| 160 | } |
||
| 161 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.