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 |
||
12 | trait ArgumentAwarePluginTrait { |
||
13 | use TypedPluginTrait; |
||
14 | |||
15 | /** |
||
16 | * Build the arguments list. |
||
17 | * |
||
18 | * @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
||
19 | * Instance of the schema manager to resolve dependencies. |
||
20 | * |
||
21 | * @return \Youshido\GraphQL\Field\InputFieldInterface[] |
||
22 | * The list of arguments. |
||
23 | */ |
||
24 | View Code Duplication | protected function buildArguments(PluggableSchemaBuilderInterface $schemaBuilder) { |
|
47 | |||
48 | /** |
||
49 | * Build the argument type. |
||
50 | * |
||
51 | * @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
||
52 | * Instance of the schema manager to resolve dependencies. |
||
53 | * @param array|string $argument |
||
54 | * The argument definition array or type name. |
||
55 | * |
||
56 | * @return \Youshido\GraphQL\Type\TypeInterface |
||
57 | * The type object. |
||
58 | */ |
||
59 | View Code Duplication | protected function buildArgumentType(PluggableSchemaBuilderInterface $schemaBuilder, $argument) { |
|
69 | |||
70 | } |
||
71 |
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.