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 |
||
| 18 | class UnorderedList |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @deprecated |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | public static $defaultTag = 'ul'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @deprecated |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $tag; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | protected $options = []; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var array |
||
| 40 | */ |
||
| 41 | protected $items = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param array $options |
||
| 45 | */ |
||
| 46 | 2 | public function __construct($options = []) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | 2 | public function __toString() |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $label |
||
| 67 | * @param array $options |
||
| 68 | * @return static |
||
| 69 | */ |
||
| 70 | public function item($label, $options = []) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @deprecated |
||
| 90 | * Change html tag. |
||
| 91 | * @param string $tag |
||
| 92 | * @return static |
||
| 93 | * @throws \yii\base\InvalidParamException |
||
| 94 | */ |
||
| 95 | 1 | public function tag($tag) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * @deprecated |
||
| 106 | * @param string|null $tag |
||
| 107 | * @param array $options |
||
| 108 | * @return string |
||
| 109 | * @throws \yii\base\InvalidConfigException |
||
| 110 | */ |
||
| 111 | View Code Duplication | public function render($tag = null, $options = []) |
|
| 123 | } |
||
| 124 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.