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 |
||
13 | View Code Duplication | class ConfigurationRoutes extends RouteSubscriberBase { |
|
|
|||
14 | |||
15 | /** |
||
16 | * The graphql schema plugin manager. |
||
17 | * |
||
18 | * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager |
||
19 | */ |
||
20 | protected $schemaManager; |
||
21 | |||
22 | /** |
||
23 | * Constructs a QueryRoutes object. |
||
24 | * |
||
25 | * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager $schemaManager |
||
26 | * The graphql schema plugin manager. |
||
27 | */ |
||
28 | public function __construct(SchemaPluginManager $schemaManager) { |
||
31 | |||
32 | /** |
||
33 | * Alters existing routes for a specific collection. |
||
34 | * |
||
35 | * @param \Symfony\Component\Routing\RouteCollection $collection |
||
36 | * The route collection for adding routes. |
||
37 | */ |
||
38 | protected function alterRoutes(RouteCollection $collection) { |
||
57 | |||
58 | } |
||
59 |
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.