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 File extends Model{ |
||
|
|
|||
| 11 | |||
| 12 | /** |
||
| 13 | * get all files. |
||
| 14 | * |
||
| 15 | * @access public |
||
| 16 | * @param integer $pageNum |
||
| 17 | * @return array |
||
| 18 | * |
||
| 19 | */ |
||
| 20 | View Code Duplication | public function getAll($pageNum = 1){ |
|
| 40 | |||
| 41 | /** |
||
| 42 | * get file by Id. |
||
| 43 | * |
||
| 44 | * @access public |
||
| 45 | * @param string $fileId |
||
| 46 | * @return array Array holds the data of the file |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function getById($fileId){ |
|
| 63 | |||
| 64 | /** |
||
| 65 | * get file by hashed name. |
||
| 66 | * files are unique by the hashed file name(= hash(original filename . extension)). |
||
| 67 | * |
||
| 68 | * @access public |
||
| 69 | * @param string $hashedFileName |
||
| 70 | * @return array Array holds the data of the file |
||
| 71 | */ |
||
| 72 | View Code Duplication | public function getByHashedName($hashedFileName){ |
|
| 88 | |||
| 89 | /** |
||
| 90 | * create file. |
||
| 91 | * |
||
| 92 | * @access public |
||
| 93 | * @param integer $userId |
||
| 94 | * @param array $fileData |
||
| 95 | * @return array Array holds the created file |
||
| 96 | * @throws Exception If file couldn't be created |
||
| 97 | */ |
||
| 98 | public function create($userId, $fileData){ |
||
| 129 | |||
| 130 | /** |
||
| 131 | * deletes file. |
||
| 132 | * This method overrides the deleteById() method in Model class. |
||
| 133 | * |
||
| 134 | * @access public |
||
| 135 | * @param array $id |
||
| 136 | * @throws Exception If failed to delete the file |
||
| 137 | * |
||
| 138 | */ |
||
| 139 | public function deleteById($id){ |
||
| 160 | |||
| 161 | } |
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.