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 |
||
| 11 | class StringHelper |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * upper letters |
||
| 15 | * |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $upperLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
||
| 19 | |||
| 20 | |||
| 21 | public function plural($value) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param $string |
||
| 28 | * @param string $separator |
||
| 29 | * @return mixed |
||
| 30 | */ |
||
| 31 | 1 | public function toTag($string, $separator = '_') |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @param $string |
||
| 42 | * @return mixed |
||
| 43 | */ |
||
| 44 | 1 | public function upperFirstLetter($string) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @param $string |
||
| 52 | * @return mixed |
||
| 53 | */ |
||
| 54 | 1 | public function lowerFirstLetter($string) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @param $string |
||
| 62 | * @return mixed |
||
| 63 | */ |
||
| 64 | 1 | View Code Duplication | public function toCamel($string) |
| 72 | |||
| 73 | /** |
||
| 74 | * @param $string |
||
| 75 | * @return mixed |
||
| 76 | */ |
||
| 77 | 1 | View Code Duplication | public function toPascal($string) |
| 85 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.