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 Serie |
||
|
|
|||
| 10 | { |
||
| 11 | const ALL_SERIES_ID = "cops:series"; |
||
| 12 | const SERIES_COLUMNS = "series.id as id, series.name as name, series.sort as sort, count(*) as count"; |
||
| 13 | 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"; |
||
| 14 | 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"; |
||
| 15 | |||
| 16 | public $id; |
||
| 17 | public $name; |
||
| 18 | |||
| 19 | 49 | public function __construct($post) { |
|
| 23 | |||
| 24 | 49 | public function getUri () { |
|
| 27 | |||
| 28 | 7 | public function getEntryId () { |
|
| 31 | |||
| 32 | 18 | public static function getCount() { |
|
| 36 | |||
| 37 | 48 | View Code Duplication | public static function getSerieByBookId ($bookId) { |
| 47 | |||
| 48 | 1 | View Code Duplication | public static function getSerieById ($serieId) { |
| 56 | |||
| 57 | 2 | public static function getAllSeries() { |
|
| 60 | |||
| 61 | 22 | public static function getAllSeriesByQuery($query) { |
|
| 64 | } |
||
| 65 |
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.