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 Helper |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Merges two or more arrays into one recursively. |
||
| 17 | * Based on Yii2 yii\helpers\BaseArrayHelper::merge. |
||
| 18 | * @param array $a array to be merged to |
||
| 19 | * @param array $b array to be merged from |
||
| 20 | * @return array the merged array |
||
| 21 | */ |
||
| 22 | View Code Duplication | public static function mergeConfig($a, $b) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Dumps closure object to string. |
||
| 50 | * Based on http://www.metashock.de/2013/05/dump-source-code-of-closure-in-php/ |
||
| 51 | * @param Closure $c |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | public static function dumpClosure(Closure $c) { |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Returns a parsable string representation of given value. |
||
| 86 | * In contrast to var_dump outputs Closures as PHP code. |
||
| 87 | * @param mixed $value |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | public static function exportVar($value) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Collects closures from given input. |
||
| 107 | * Substitutes closures with a tag. |
||
| 108 | * @param mixed $input will be changed |
||
| 109 | * @return array array of found closures |
||
| 110 | */ |
||
| 111 | private static function collectClosures(&$input) { |
||
| 129 | } |
||
| 130 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.