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 |
||
| 30 | class FormWidget extends AdminWidget implements |
||
| 31 | FormInterface, |
||
| 32 | LayoutAwareInterface |
||
| 33 | { |
||
| 34 | use FormTrait; |
||
| 35 | use LayoutAwareTrait; |
||
| 36 | |||
| 37 | protected $sidebars = []; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var WidgetFactory $widgetFactory |
||
| 41 | */ |
||
| 42 | private $widgetFactory; |
||
| 43 | |||
| 44 | public function setDependencies(Container $container) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param array|null $data |
||
| 52 | * @return FormGroupInterface |
||
| 53 | */ |
||
| 54 | public function createGroup(array $data = null) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param array $data |
||
| 70 | * @return FormPropertyInterface |
||
| 71 | */ |
||
| 72 | public function createFormProperty(array $data = null) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * |
||
| 85 | */ |
||
| 86 | public function setSidebars(array $sidebars) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param array|FormSidebarWidget $sidebar |
||
| 97 | * @throws InvalidArgumentException |
||
| 98 | * @return FormWidget Chainable |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function addSidebar($sidebarIdent, $sidebar) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @return FormSidebarWidget |
||
| 126 | */ |
||
| 127 | View Code Duplication | public function sidebars() |
|
| 145 | |||
| 146 | /** |
||
| 147 | * To be called with uasort(). |
||
| 148 | * |
||
| 149 | * @param FormGroupInterface $a Item "a" to compare, for sorting. |
||
| 150 | * @param FormGroupInterface $b Item "b" to compaer, for sorting. |
||
| 151 | * @return integer Sorting value: -1, 0, or 1 |
||
| 152 | */ |
||
| 153 | View Code Duplication | protected static function sortSidebarsByPriority(FormGroupInterface $a, FormGroupInterface $b) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * @return WidgetFactory |
||
| 168 | */ |
||
| 169 | private function widgetFactory() |
||
| 176 | } |
||
| 177 |
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.