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 Entry |
||
|
|
|||
| 10 | { |
||
| 11 | public $title; |
||
| 12 | public $id; |
||
| 13 | public $content; |
||
| 14 | public $numberOfElement; |
||
| 15 | public $contentType; |
||
| 16 | public $linkArray; |
||
| 17 | public $localUpdated; |
||
| 18 | public $className; |
||
| 19 | private static $updated = NULL; |
||
| 20 | |||
| 21 | public static $icons = array( |
||
| 22 | Author::ALL_AUTHORS_ID => 'images/author.png', |
||
| 23 | Serie::ALL_SERIES_ID => 'images/serie.png', |
||
| 24 | Book::ALL_RECENT_BOOKS_ID => 'images/recent.png', |
||
| 25 | Tag::ALL_TAGS_ID => 'images/tag.png', |
||
| 26 | Language::ALL_LANGUAGES_ID => 'images/language.png', |
||
| 27 | CustomColumnType::ALL_CUSTOMS_ID => 'images/custom.png', |
||
| 28 | Rating::ALL_RATING_ID => 'images/rating.png', |
||
| 29 | "cops:books$" => 'images/allbook.png', |
||
| 30 | "cops:books:letter" => 'images/allbook.png', |
||
| 31 | Publisher::ALL_PUBLISHERS_ID => 'images/publisher.png' |
||
| 32 | ); |
||
| 33 | |||
| 34 | public function getUpdatedTime () { |
||
| 43 | |||
| 44 | 7 | View Code Duplication | public function getNavLink () { |
| 54 | |||
| 55 | 109 | public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "", $pcount = 0) { |
|
| 78 | } |
||
| 79 |
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.