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 |
||
20 | class StringStream |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Content of stream |
||
25 | * @var string |
||
26 | */ |
||
27 | private static $string = []; |
||
28 | |||
29 | /** |
||
30 | * Whether this stream can be read |
||
31 | * @var boolean |
||
32 | */ |
||
33 | private $read; |
||
34 | |||
35 | /** |
||
36 | * Whether this stream can be written |
||
37 | * @var boolean |
||
38 | */ |
||
39 | private $write; |
||
40 | |||
41 | /** |
||
42 | * Options |
||
43 | * @var int |
||
44 | */ |
||
45 | private $options; |
||
46 | |||
47 | /** |
||
48 | * Current position within stream |
||
49 | * @var int |
||
50 | */ |
||
51 | private $position; |
||
52 | private $path; |
||
53 | private static $registered = false; |
||
54 | |||
55 | /** |
||
56 | * Open stream |
||
57 | * @param string $aPath |
||
58 | * @param string $aMode |
||
59 | * @param int $aOptions |
||
60 | * @param string $aOpenedPath |
||
61 | * @return boolean |
||
62 | */ |
||
63 | function stream_open($aPath, $aMode, $aOptions, &$aOpenedPath) |
||
128 | |||
129 | /** |
||
130 | * Read from stream |
||
131 | * @param int $aBytes number of bytes to return |
||
132 | * @return string |
||
133 | */ |
||
134 | function stream_read($aBytes) |
||
144 | |||
145 | /** |
||
146 | * Write to stream |
||
147 | * @param string $aData data to write |
||
148 | * @return int |
||
149 | */ |
||
150 | function stream_write($aData) |
||
162 | |||
163 | /** |
||
164 | * Return current position |
||
165 | * @return int |
||
166 | */ |
||
167 | function stream_tell() |
||
171 | |||
172 | /** |
||
173 | * Return if EOF |
||
174 | * @return boolean |
||
175 | */ |
||
176 | function stream_eof() |
||
180 | |||
181 | /** |
||
182 | * Seek to new position |
||
183 | * @param int $aOffset |
||
184 | * @param int $aWhence |
||
185 | * @return boolean |
||
186 | */ |
||
187 | function stream_seek($aOffset, $aWhence) |
||
216 | |||
217 | /** |
||
218 | * Truncate to given size |
||
219 | * @param int $aSize |
||
220 | */ |
||
221 | public function stream_truncate($aSize) |
||
230 | |||
231 | /** |
||
232 | * Return info about stream |
||
233 | * @return array |
||
234 | */ |
||
235 | public function stream_stat() |
||
251 | |||
252 | /** |
||
253 | * Return info about stream |
||
254 | * @param string $aPath |
||
255 | * @param array $aOptions |
||
256 | * @return array |
||
257 | */ |
||
258 | public function url_stat($aPath, $aOptions) |
||
263 | |||
264 | public static function register() |
||
276 | |||
277 | public static function unregister() |
||
284 | } |
||
285 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.