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 Tag |
||
|
|
|||
| 10 | { |
||
| 11 | const ALL_TAGS_ID = "cops:tags"; |
||
| 12 | const TAG_COLUMNS = "tags.id as id, tags.name as name, count(*) as count"; |
||
| 13 | const SQL_ALL_TAGS = "select {0} from tags, books_tags_link where tags.id = tag group by tags.id, tags.name order by tags.name"; |
||
| 14 | |||
| 15 | public $id; |
||
| 16 | public $name; |
||
| 17 | |||
| 18 | 17 | public function __construct($post) { |
|
| 22 | |||
| 23 | 8 | public function getUri () { |
|
| 26 | |||
| 27 | 8 | public function getEntryId () { |
|
| 30 | |||
| 31 | 18 | public static function getCount() { |
|
| 35 | |||
| 36 | 1 | View Code Duplication | public static function getTagById ($tagId) { |
| 44 | |||
| 45 | 2 | public static function getAllTags() { |
|
| 48 | |||
| 49 | 23 | public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 63 | } |
||
| 64 |
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.