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 Helper |
||
21 | { |
||
22 | 3 | public static function isYii20() |
|
26 | |||
27 | 4 | public static function bad2sep($str, $separator = '-') |
|
31 | |||
32 | 4 | public static function id2camel($id, $separator = '-') |
|
37 | |||
38 | 1 | public static function camel2id($name, $separator = '-', $strict = false) |
|
42 | |||
43 | public static function file2template($file, $separator = '-') |
||
47 | |||
48 | View Code Duplication | public static function csplit($input, $delimiter = ',') |
|
57 | |||
58 | View Code Duplication | public static function asplit($input) |
|
67 | |||
68 | public static function ksplit($input, $delimiter = ',') |
||
77 | |||
78 | public static function getPublicVars($subj) |
||
82 | |||
83 | 2 | public static function titleize($str, $ucAll = true) |
|
87 | |||
88 | /** |
||
89 | * Recursively removes duplicate values from non-associative arrays. |
||
90 | */ |
||
91 | public static function uniqueConfig($array) |
||
95 | } |
||
96 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.