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 |
||
31 | class XoopsZipDownloader extends XoopsDownloader |
||
32 | { |
||
33 | /** |
||
34 | * Constructor |
||
35 | * |
||
36 | * @param string $ext extention |
||
37 | * @param string $mimyType mimi type |
||
38 | * |
||
39 | * @return XoopsZipDownloader |
||
40 | */ |
||
|
|||
41 | |||
42 | 1 | public function __construct($ext = '.zip', $mimyType = 'application/x-zip') |
|
48 | |||
49 | /** |
||
50 | * Add file |
||
51 | * |
||
52 | * @param string $filepath path |
||
53 | * @param string $newfilename name |
||
54 | * |
||
55 | * @return false|null |
||
56 | */ |
||
57 | View Code Duplication | public function addFile($filepath, $newfilename = null) |
|
70 | |||
71 | /** |
||
72 | * Add Binary File |
||
73 | * |
||
74 | * @param string $filepath path |
||
75 | * @param string $newfilename name |
||
76 | * |
||
77 | * @return false|null |
||
78 | */ |
||
79 | View Code Duplication | public function addBinaryFile($filepath, $newfilename = null) |
|
92 | |||
93 | /** |
||
94 | * Add File Data |
||
95 | * |
||
96 | * @param string &$data data |
||
97 | * @param string $filename name |
||
98 | * @param int $time time |
||
99 | * |
||
100 | * @return result |
||
101 | */ |
||
102 | public function addFileData(&$data, $filename, $time = 0) |
||
107 | |||
108 | /** |
||
109 | * Add Binary File Data |
||
110 | * |
||
111 | * @param string &$data data |
||
112 | * @param string $filename name |
||
113 | * @param int $time file time |
||
114 | * |
||
115 | * @return result|null |
||
116 | */ |
||
117 | public function addBinaryFileData(&$data, $filename, $time = 0) |
||
122 | |||
123 | /** |
||
124 | * Fownload Data as a Zip file |
||
125 | * |
||
126 | * @param string $name zip name |
||
127 | * @param bool $gzip unused |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | public function download($name, $gzip = true) |
||
139 | } |
||
140 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.