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 |
||
| 7 | class Nip_File extends Nip_Object |
||
| 8 | {
|
||
| 9 | |||
| 10 | protected $_path; |
||
| 11 | protected $_name; |
||
| 12 | protected $_extension; |
||
| 13 | |||
| 14 | public function __construct($path = false) |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param $target |
||
| 23 | * @return $this |
||
| 24 | * @throws Nip_File_Exception |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function move($target) |
|
| 40 | |||
| 41 | public function getPath() |
||
| 45 | |||
| 46 | public function setPath($path) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param $target |
||
| 56 | * @return $this |
||
| 57 | * @throws Nip_File_Exception |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function copy($target) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * @param string $target |
||
| 76 | * @return Nip_Process |
||
| 77 | */ |
||
| 78 | View Code Duplication | public function unzip($target) |
|
| 89 | |||
| 90 | public function download($filename = false, $contentType = false) |
||
| 111 | |||
| 112 | public function getName() |
||
| 116 | |||
| 117 | public function getSize() |
||
| 121 | |||
| 122 | public function delete() |
||
| 126 | |||
| 127 | public function getExtension() |
||
| 131 | |||
| 132 | public function getTime() |
||
| 136 | |||
| 137 | public function getMimeType() |
||
| 151 | |||
| 152 | } |
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.