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 $authorizationChecker |
||
27 | * @param bool $isEnabledVersionChecker |
||
28 | */ |
||
29 | 6 | public function __construct(AuthorizationCheckerInterface $authorizationChecker, $isEnabledVersionChecker) |
|
34 | |||
35 | /** |
||
36 | * In this method you can add children for a specific parent, but also remove and change the already created children |
||
37 | * |
||
38 | * @param MenuBuilder $menu The MenuBuilder |
||
39 | * @param MenuItem[] &$children The current children |
||
40 | * @param MenuItem $parent The parent Menu item |
||
|
|||
41 | * @param Request $request The Request |
||
42 | */ |
||
43 | 5 | public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null) |
|
86 | } |
||
87 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.