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 |
||
11 | class SettingsMenuAdaptor implements MenuAdaptorInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var AuthorizationCheckerInterface |
||
15 | */ |
||
16 | private $authorizationChecker; |
||
17 | |||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | private $isEnabledVersionChecker; |
||
22 | |||
23 | /** |
||
24 | * Constructor |
||
25 | * |
||
26 | * @param AuthorizationCheckerInterface $container |
||
|
|||
27 | */ |
||
28 | public function __construct(AuthorizationCheckerInterface $authorizationChecker, $isEnabledVersionChecker) |
||
33 | |||
34 | /** |
||
35 | * In this method you can add children for a specific parent, but also remove and change the already created children |
||
36 | * |
||
37 | * @param MenuBuilder $menu The MenuBuilder |
||
38 | * @param MenuItem[] &$children The current children |
||
39 | * @param MenuItem $parent The parent Menu item |
||
40 | * @param Request $request The Request |
||
41 | */ |
||
42 | public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null) |
||
87 | } |
||
88 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.