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 |
||
| 17 | class TrackMapper extends BaseMapper { |
||
| 18 | |||
| 19 | public function __construct(IDBConnection $db){ |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string $condition |
||
| 25 | */ |
||
| 26 | private function makeSelectQueryWithoutUserId($condition){ |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param string $condition |
||
| 36 | */ |
||
| 37 | private function makeSelectQuery($condition=null){ |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param string $userId |
||
| 43 | * @param integer $limit |
||
| 44 | * @param integer $offset |
||
| 45 | * @return Track[] |
||
| 46 | */ |
||
| 47 | public function findAll($userId, $limit=null, $offset=null){ |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param integer $artistId |
||
| 55 | * @param string $userId |
||
| 56 | * @return Track[] |
||
| 57 | */ |
||
| 58 | public function findAllByArtist($artistId, $userId){ |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param integer $albumId |
||
| 67 | * @param string $userId |
||
| 68 | * @param integer $artistId |
||
| 69 | * @return Track[] |
||
| 70 | */ |
||
| 71 | public function findAllByAlbum($albumId, $userId, $artistId = null){ |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param string $userId |
||
| 84 | * @return int[] |
||
| 85 | */ |
||
| 86 | public function findAllFileIds($userId){ |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param integer $id |
||
| 95 | * @param string $userId |
||
| 96 | * @return Track |
||
| 97 | */ |
||
| 98 | public function find($id, $userId){ |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param integer $fileId |
||
| 106 | * @param string $userId |
||
| 107 | * @return Track |
||
| 108 | */ |
||
| 109 | public function findByFileId($fileId, $userId){ |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @param integer $fileId |
||
| 117 | * @return Track[] |
||
| 118 | */ |
||
| 119 | public function findAllByFileId($fileId){ |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param integer $artistId |
||
| 128 | * @param string $userId |
||
| 129 | * @return integer |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function countByArtist($artistId, $userId){ |
|
| 139 | |||
| 140 | /** |
||
| 141 | * @param integer $albumId |
||
| 142 | * @param string $userId |
||
| 143 | * @return integer |
||
| 144 | */ |
||
| 145 | View Code Duplication | public function countByAlbum($albumId, $userId){ |
|
| 153 | |||
| 154 | /** |
||
| 155 | * @param string $name |
||
| 156 | * @param string $userId |
||
| 157 | * @param bool $fuzzy |
||
| 158 | * @return Track[] |
||
| 159 | */ |
||
| 160 | View Code Duplication | public function findAllByName($name, $userId, $fuzzy = false){ |
|
| 171 | |||
| 172 | /** |
||
| 173 | * @param string $name |
||
| 174 | * @param string $userId |
||
| 175 | * @return Track[] |
||
| 176 | */ |
||
| 177 | public function findAllByNameRecursive($name, $userId){ |
||
| 186 | } |
||
| 187 |