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 Data extends Base |
||
|
|
|||
| 10 | { |
||
| 11 | public $id; |
||
| 12 | public $name; |
||
| 13 | public $format; |
||
| 14 | public $realFormat; |
||
| 15 | public $extension; |
||
| 16 | public $book; |
||
| 17 | |||
| 18 | public static $mimetypes = array( |
||
| 19 | 'aac' => 'audio/aac', |
||
| 20 | 'azw' => 'application/x-mobipocket-ebook', |
||
| 21 | 'azw1' => 'application/x-topaz-ebook', |
||
| 22 | 'azw2' => 'application/x-kindle-application', |
||
| 23 | 'azw3' => 'application/x-mobi8-ebook', |
||
| 24 | 'cbz' => 'application/x-cbz', |
||
| 25 | 'cbr' => 'application/x-cbr', |
||
| 26 | 'djv' => 'image/vnd.djvu', |
||
| 27 | 'djvu' => 'image/vnd.djvu', |
||
| 28 | 'doc' => 'application/msword', |
||
| 29 | 'epub' => 'application/epub+zip', |
||
| 30 | 'fb2' => 'text/fb2+xml', |
||
| 31 | 'ibooks'=> 'application/x-ibooks+zip', |
||
| 32 | 'kepub' => 'application/epub+zip', |
||
| 33 | 'kobo' => 'application/x-koboreader-ebook', |
||
| 34 | 'm4a' => 'audio/mp4', |
||
| 35 | 'mobi' => 'application/x-mobipocket-ebook', |
||
| 36 | 'mp3' => 'audio/mpeg', |
||
| 37 | 'lit' => 'application/x-ms-reader', |
||
| 38 | 'lrs' => 'text/x-sony-bbeb+xml', |
||
| 39 | 'lrf' => 'application/x-sony-bbeb', |
||
| 40 | 'lrx' => 'application/x-sony-bbeb', |
||
| 41 | 'ncx' => 'application/x-dtbncx+xml', |
||
| 42 | 'opf' => 'application/oebps-package+xml', |
||
| 43 | 'otf' => 'application/x-font-opentype', |
||
| 44 | 'pdb' => 'application/vnd.palm', |
||
| 45 | 'pdf' => 'application/pdf', |
||
| 46 | 'prc' => 'application/x-mobipocket-ebook', |
||
| 47 | 'rtf' => 'application/rtf', |
||
| 48 | 'svg' => 'image/svg+xml', |
||
| 49 | 'ttf' => 'application/x-font-truetype', |
||
| 50 | 'tpz' => 'application/x-topaz-ebook', |
||
| 51 | 'wav' => 'audio/wav', |
||
| 52 | 'wmf' => 'image/wmf', |
||
| 53 | 'xhtml' => 'application/xhtml+xml', |
||
| 54 | 'xpgt' => 'application/adobe-page-template+xml', |
||
| 55 | 'zip' => 'application/zip' |
||
| 56 | ); |
||
| 57 | |||
| 58 | 63 | public function __construct($post, $book = null) { |
|
| 66 | |||
| 67 | 53 | public function isKnownType () { |
|
| 70 | |||
| 71 | 53 | public function getMimeType () { |
|
| 88 | |||
| 89 | 1 | public function isEpubValidOnKobo () { |
|
| 92 | |||
| 93 | 50 | public function getFilename () { |
|
| 96 | |||
| 97 | 1 | public function getUpdatedFilename () { |
|
| 100 | |||
| 101 | 1 | public function getUpdatedFilenameEpub () { |
|
| 104 | |||
| 105 | 1 | public function getUpdatedFilenameKepub () { |
|
| 110 | |||
| 111 | 49 | public function getDataLink ($rel, $title = NULL) { |
|
| 120 | |||
| 121 | 5 | public function getHtmlLink () { |
|
| 124 | |||
| 125 | 2 | public function getLocalPath () { |
|
| 128 | |||
| 129 | 2 | public function getHtmlLinkWithRewriting ($title = NULL) { |
|
| 146 | |||
| 147 | 62 | View Code Duplication | public static function getDataByBook ($book) { |
| 159 | |||
| 160 | 19 | public static function handleThumbnailLink ($urlParam, $height) { |
|
| 178 | |||
| 179 | 49 | public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
|
| 208 | } |
||
| 209 |
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.