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 | View Code Duplication | class Serie extends Base { |
|
| 10 | const ALL_SERIES_ID = "cops:series"; |
||
| 11 | const SERIES_COLUMNS = "series.id as id, series.name as name, series.sort as sort, count(*) as count"; |
||
| 12 | const SQL_ALL_SERIES = "select {0} from series, books_series_link where series.id = series group by series.id, series.name, series.sort order by series.sort"; |
||
| 13 | const SQL_SERIES_FOR_SEARCH = "select {0} from series, books_series_link where series.id = series and upper (series.name) like ? group by series.id, series.name, series.sort order by series.sort"; |
||
| 14 | |||
| 15 | public $id; |
||
| 16 | public $name; |
||
| 17 | |||
| 18 | 46 | public function __construct($post) { |
|
| 22 | |||
| 23 | 46 | public function getUri () { |
|
| 26 | |||
| 27 | 7 | public function getEntryId () { |
|
| 30 | |||
| 31 | 7 | public static function getCount() { |
|
| 35 | |||
| 36 | 45 | public static function getSerieByBookId ($bookId) { |
|
| 46 | |||
| 47 | 1 | public static function getSerieById ($serieId) { |
|
| 55 | |||
| 56 | 2 | public static function getAllSeries() { |
|
| 59 | |||
| 60 | 22 | public static function getAllSeriesByQuery($query) { |
|
| 63 | } |
||
| 64 |
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.