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 |
||
| 9 | class NewsFeed extends Model{ |
||
|
|
|||
| 10 | |||
| 11 | /** |
||
| 12 | * get all news feed. |
||
| 13 | * |
||
| 14 | * @access public |
||
| 15 | * @param integer $pageNum |
||
| 16 | * @return array |
||
| 17 | * |
||
| 18 | */ |
||
| 19 | View Code Duplication | public function getAll($pageNum = 1){ |
|
| 38 | |||
| 39 | /** |
||
| 40 | * get news feed by Id. |
||
| 41 | * |
||
| 42 | * @param string $newsfeedId |
||
| 43 | * @return array |
||
| 44 | */ |
||
| 45 | View Code Duplication | public function getById($newsfeedId){ |
|
| 60 | |||
| 61 | /** |
||
| 62 | * create news feed. |
||
| 63 | * |
||
| 64 | * @param integer $userId |
||
| 65 | * @param string $content |
||
| 66 | * @return array feed created |
||
| 67 | * @throws Exception if feed couldn't be created |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function create($userId, $content){ |
|
| 93 | |||
| 94 | /** |
||
| 95 | * update news feed. |
||
| 96 | * |
||
| 97 | * @param string $newsfeedId |
||
| 98 | * @param string $content |
||
| 99 | * @return array feed created |
||
| 100 | * @throws Exception if feed couldn't be updated |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function update($newsfeedId, $content){ |
|
| 125 | |||
| 126 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.