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 ConfigMenuAdaptor implements MenuAdaptorInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var array $configuration |
||
15 | */ |
||
16 | private $configuration; |
||
17 | |||
18 | /** |
||
19 | * @var AuthorizationCheckerInterface |
||
20 | */ |
||
21 | private $authorizationChecker; |
||
22 | |||
23 | /** |
||
24 | * @param array $configuration |
||
25 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
26 | */ |
||
27 | public function __construct($configuration, AuthorizationCheckerInterface $authorizationChecker) |
||
32 | |||
33 | /** |
||
34 | * In this method you can add children for a specific parent, but also remove and change the already created children |
||
35 | * |
||
36 | * @param MenuBuilder $menu The MenuBuilder |
||
37 | * @param MenuItem[] &$children The current children |
||
38 | * @param MenuItem $parent The parent Menu item |
||
|
|||
39 | * @param Request $request The Request |
||
40 | */ |
||
41 | public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null) |
||
73 | } |
||
74 |
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.