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 |
||
23 | class DirectiveDelegate extends DefinitionDelegate |
||
24 | { |
||
25 | /** |
||
26 | * @param DocumentInterface|Document $document |
||
27 | * @return Definition |
||
28 | */ |
||
29 | protected function bootDefinition(DocumentInterface $document): Definition |
||
33 | |||
34 | /** |
||
35 | * @param Definition|DirectiveDefinition $definition |
||
36 | */ |
||
37 | protected function before(Definition $definition): void |
||
41 | |||
42 | /** |
||
43 | * @param DirectiveDefinition $directive |
||
44 | */ |
||
45 | private function bootLocations(DirectiveDefinition $directive): void |
||
56 | |||
57 | /** |
||
58 | * @param DirectiveDefinition $directive |
||
59 | * @param DirectiveLocation $location |
||
60 | * @throws \Railt\SDL\Exception\CompilerException |
||
61 | */ |
||
62 | private function verifyDuplication(DirectiveDefinition $directive, DirectiveLocation $location): void |
||
71 | |||
72 | /** |
||
73 | * @param DirectiveDefinition $definition |
||
74 | * @return iterable|DirectiveLocation[] |
||
75 | */ |
||
76 | private function getLocations(DirectiveDefinition $definition): iterable |
||
83 | |||
84 | /** |
||
85 | * @param DirectiveLocation $location |
||
86 | * @throws \Railt\SDL\Exception\CompilerException |
||
87 | */ |
||
88 | private function verifyLocation(DirectiveLocation $location): void |
||
98 | } |
||
99 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.