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 |
||
| 24 | class MylinksUtility |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * Sanitize input variables |
||
| 28 | * @param string $global the input array ($_REQUEST, $_GET, $_POST) |
||
| 29 | * @param unknown_type $key the array key for variable to clean |
||
| 30 | * @param string|unknown_type $default the default value to use if filter fails |
||
| 31 | * @param string $type the variable type (string, email, url, int) |
||
| 32 | * @param array $limit 'min' 'max' keys - the lower/upper limit for integer values |
||
|
|
|||
| 33 | * @return Ambigous|number <boolean, unknown> |
||
| 34 | */ |
||
| 35 | public static function mylinks_cleanVars(&$global, $key, $default = '', $type = 'int', $limit = null) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * |
||
| 68 | * Temporary patch for errorHandler processing |
||
| 69 | * @deprecated |
||
| 70 | * @param string $msg message to display |
||
| 71 | * @param int $pages number of pages to jump back for link |
||
| 72 | * @param string $type error||info to add errorMsg CSS to display |
||
| 73 | * @return null |
||
| 74 | */ |
||
| 75 | public static function show_message($msg, $pages = 1, $type = 'error') |
||
| 96 | } |
||
| 97 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.