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 |
||
5 | use KyleMassacre\Menus\Contracts\MenuItemContract; |
||
6 | |||
7 | class NavbarRightPresenter extends NavbarPresenter |
||
8 | { |
||
9 | /** |
||
10 | * {@inheritdoc} |
||
11 | */ |
||
12 | public function getOpenTagWrapper(): ?string |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | public function getMenuWithDropDownWrapper(MenuItemContract $item): ?string |
||
34 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.