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 |
||
30 | class AggregateControllerQueryProvider implements QueryProviderInterface |
||
31 | { |
||
32 | /** |
||
33 | * @var Reader |
||
34 | */ |
||
35 | private $annotationReader; |
||
36 | /** |
||
37 | * @var TypeMapperInterface |
||
38 | */ |
||
39 | private $typeMapper; |
||
40 | /** |
||
41 | * @var HydratorInterface |
||
42 | */ |
||
43 | private $hydrator; |
||
44 | /** |
||
45 | * @var array|\string[] |
||
46 | */ |
||
47 | private $controllers; |
||
48 | /** |
||
49 | * @var ContainerInterface |
||
50 | */ |
||
51 | private $container; |
||
52 | /** |
||
53 | * @var AuthenticationServiceInterface |
||
54 | */ |
||
55 | private $authenticationService; |
||
56 | /** |
||
57 | * @var AuthorizationServiceInterface |
||
58 | */ |
||
59 | private $authorizationService; |
||
60 | |||
61 | /** |
||
62 | * @param string[] $controllers A list of controllers name in the container. |
||
63 | */ |
||
64 | View Code Duplication | public function __construct(array $controllers, ContainerInterface $container, Reader $annotationReader, TypeMapperInterface $typeMapper, HydratorInterface $hydrator, AuthenticationServiceInterface $authenticationService, AuthorizationServiceInterface $authorizationService) |
|
74 | |||
75 | /** |
||
76 | * @return Field[] |
||
77 | */ |
||
78 | View Code Duplication | public function getQueries(): array |
|
90 | |||
91 | /** |
||
92 | * @return Field[] |
||
93 | */ |
||
94 | View Code Duplication | public function getMutations(): array |
|
106 | } |
||
107 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.