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 |
||
25 | class DirectiveDelegate extends TypeDefinitionDelegate |
||
26 | { |
||
27 | /** |
||
28 | * @param DocumentInterface|Document $document |
||
29 | * @return Definition |
||
30 | */ |
||
31 | protected function create(DocumentInterface $document): Definition |
||
35 | |||
36 | /** |
||
37 | * @return void |
||
38 | */ |
||
39 | protected function register(): void |
||
45 | |||
46 | /** |
||
47 | * @param DirectiveDefinition|TypeDefinition $directive |
||
48 | */ |
||
49 | private function bootLocations(DirectiveDefinition $directive): void |
||
60 | |||
61 | /** |
||
62 | * @param DirectiveDefinition $directive |
||
63 | * @param DirectiveLocation $location |
||
64 | * @throws \Railt\SDL\Exception\CompilerException |
||
65 | */ |
||
66 | private function verifyDuplication(DirectiveDefinition $directive, DirectiveLocation $location): void |
||
75 | |||
76 | /** |
||
77 | * @param DirectiveDefinition $definition |
||
78 | * @return iterable|DirectiveLocation[] |
||
79 | */ |
||
80 | private function getLocations(DirectiveDefinition $definition): iterable |
||
87 | |||
88 | /** |
||
89 | * @param DirectiveLocation $location |
||
90 | * @throws \Railt\SDL\Exception\CompilerException |
||
91 | */ |
||
92 | private function verifyLocation(DirectiveLocation $location): void |
||
102 | } |
||
103 |
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.