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 /** MicroFTP */ |
||
17 | final class Ftp |
||
18 | { |
||
19 | /** |
||
20 | * Last error |
||
21 | * |
||
22 | * @var string $error |
||
23 | */ |
||
24 | public $error; |
||
25 | /** |
||
26 | * FTP passive mode flag |
||
27 | * |
||
28 | * @var bool $passive |
||
29 | */ |
||
30 | public $passive = false; |
||
31 | /** |
||
32 | * SSL-FTP connection flag |
||
33 | * |
||
34 | * @var bool $ssl |
||
35 | */ |
||
36 | public $ssl = false; |
||
37 | /** |
||
38 | * System type of FTP server |
||
39 | * |
||
40 | * @var string $system_type |
||
41 | */ |
||
42 | public $system_type; |
||
43 | /** |
||
44 | * FTP host |
||
45 | * |
||
46 | * @var string $_host |
||
47 | */ |
||
48 | private $_host; |
||
49 | /** |
||
50 | * FTP port |
||
51 | * |
||
52 | * @var int $_port |
||
53 | */ |
||
54 | private $_port = 21; |
||
55 | /** |
||
56 | * FTP password |
||
57 | * |
||
58 | * @var string $_pwd |
||
59 | */ |
||
60 | private $_pwd; |
||
61 | /** |
||
62 | * FTP stream |
||
63 | * |
||
64 | * @var resource $_id |
||
65 | */ |
||
66 | private $_stream; |
||
67 | /** |
||
68 | * FTP timeout |
||
69 | * |
||
70 | * @var int $_timeout |
||
71 | */ |
||
72 | private $_timeout = 90; |
||
73 | /** |
||
74 | * FTP user |
||
75 | * |
||
76 | * @var string $_user |
||
77 | */ |
||
78 | private $_user; |
||
79 | |||
80 | /** |
||
81 | * Initialize connection params |
||
82 | * |
||
83 | * @access public |
||
84 | * |
||
85 | * @param array $params |
||
86 | * |
||
87 | * @result void |
||
88 | */ |
||
89 | public function __construct(array $params = []) |
||
97 | |||
98 | /** |
||
99 | * Auto close connection |
||
100 | */ |
||
101 | public function __destruct() |
||
105 | |||
106 | /** |
||
107 | * Close FTP connection |
||
108 | */ |
||
109 | public function close() |
||
120 | |||
121 | /** |
||
122 | * Change current directory on FTP server |
||
123 | * |
||
124 | * @param string $directory |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function cd($directory = null) |
||
138 | |||
139 | /** |
||
140 | * Set file permissions |
||
141 | * |
||
142 | * @param int $permissions (ex: 0644) |
||
143 | * @param string $remote_file |
||
144 | * |
||
145 | * @return false |
||
146 | */ |
||
147 | public function chmod($permissions = 0, $remote_file = null) |
||
157 | |||
158 | /** |
||
159 | * Connect to FTP server |
||
160 | * |
||
161 | * @return bool |
||
162 | */ |
||
163 | public function connect() |
||
185 | |||
186 | /** |
||
187 | * Delete file on FTP server |
||
188 | * |
||
189 | * @param string $remote_file |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function delete($remote_file = null) |
||
203 | |||
204 | /** |
||
205 | * Download file from server |
||
206 | * |
||
207 | * @param string $remote_file |
||
208 | * @param string $local_file |
||
209 | * @param int $mode |
||
210 | * |
||
211 | * @return bool |
||
212 | */ |
||
213 | View Code Duplication | public function get($remote_file = null, $local_file = null, $mode = FTP_ASCII) |
|
223 | |||
224 | /** |
||
225 | * Get list of files/directories in directory |
||
226 | * |
||
227 | * @param string $directory |
||
228 | * |
||
229 | * @return array |
||
230 | */ |
||
231 | public function ls($directory = null) |
||
241 | |||
242 | /** |
||
243 | * Create directory on FTP server |
||
244 | * |
||
245 | * @param string $directory |
||
246 | * |
||
247 | * @return bool |
||
248 | */ |
||
249 | View Code Duplication | public function mkdir($directory = null) |
|
259 | |||
260 | /** |
||
261 | * Upload file to server |
||
262 | * |
||
263 | * @param string $local_file |
||
264 | * @param string $remote_file |
||
265 | * @param int $mode |
||
266 | * |
||
267 | * @return bool |
||
268 | */ |
||
269 | View Code Duplication | public function put($local_file = null, $remote_file = null, $mode = FTP_ASCII) |
|
279 | |||
280 | /** |
||
281 | * Get current directory |
||
282 | * |
||
283 | * @return string |
||
284 | */ |
||
285 | public function pwd() |
||
289 | |||
290 | /** |
||
291 | * Rename file on FTP server |
||
292 | * |
||
293 | * @param string $old_name |
||
294 | * @param string $new_name |
||
295 | * |
||
296 | * @return bool |
||
297 | */ |
||
298 | public function rename($old_name = null, $new_name = null) |
||
308 | |||
309 | /** |
||
310 | * Remove directory on FTP server |
||
311 | * |
||
312 | * @param string $directory |
||
313 | * |
||
314 | * @return bool |
||
315 | */ |
||
316 | View Code Duplication | public function rmdir($directory = null) |
|
326 | } |
||
327 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..