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 |
||
| 13 | class NativeWriteStream extends NativeStream { |
||
| 14 | const CHUNK_SIZE = 1048576; // 1MB chunks |
||
| 15 | /** |
||
| 16 | * @var resource |
||
| 17 | */ |
||
| 18 | private $writeBuffer = null; |
||
| 19 | |||
| 20 | private $bufferSize = 0; |
||
| 21 | |||
| 22 | private $pos = 0; |
||
| 23 | |||
| 24 | 20 | public function stream_open($path, $mode, $options, &$opened_path) { |
|
| 30 | |||
| 31 | /** |
||
| 32 | * Wrap a stream from libsmbclient-php into a regular php stream |
||
| 33 | * |
||
| 34 | * @param \Icewind\SMB\NativeState $state |
||
| 35 | * @param resource $smbStream |
||
| 36 | * @param string $mode |
||
| 37 | * @param string $url |
||
| 38 | * @return resource |
||
| 39 | */ |
||
| 40 | 20 | View Code Duplication | public static function wrap($state, $smbStream, $mode, $url) { |
| 53 | |||
| 54 | public function stream_seek($offset, $whence = SEEK_SET) { |
||
| 62 | |||
| 63 | 20 | private function flushWrite() { |
|
| 69 | |||
| 70 | 18 | public function stream_write($data) { |
|
| 81 | |||
| 82 | 20 | public function stream_close() { |
|
| 86 | |||
| 87 | public function stream_tell() { |
||
| 90 | |||
| 91 | public function stream_read($count) { |
||
| 94 | |||
| 95 | 1 | public function stream_truncate($size) { |
|
| 100 | } |
||
| 101 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.