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 |
||
| 12 | class PKCS7Encoder |
||
| 13 | { |
||
| 14 | public static $block_size = 32; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * 对需要加密的明文进行填充补位 |
||
| 18 | * |
||
| 19 | * @param $text 需要进行填充补位操作的明文 |
||
| 20 | * |
||
| 21 | * @return 补齐明文字符串 |
||
| 22 | */ |
||
| 23 | public function encode($text) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * 对解密后的明文进行补位删除 |
||
| 44 | * |
||
| 45 | * @param decrypted 解密后的明文 |
||
| 46 | * |
||
| 47 | * @return 删除填充补位后的明文 |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function decode($text) |
|
| 58 | } |
||
| 59 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.