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 |
||
16 | abstract class InputTypePluginBase extends PluginBase implements TypeSystemPluginInterface { |
||
17 | use CacheablePluginTrait; |
||
18 | use NamedPluginTrait; |
||
19 | use TypedPluginTrait; |
||
20 | |||
21 | /** |
||
22 | * The type instance. |
||
23 | * |
||
24 | * @var \Drupal\graphql\GraphQL\Type\InputObjectType |
||
25 | */ |
||
26 | protected $definition; |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | public function getDefinition(PluggableSchemaBuilderInterface $schemaBuilder) { |
||
42 | |||
43 | /** |
||
44 | * Build the field list. |
||
45 | * |
||
46 | * @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
||
47 | * Instance of the schema manager to resolve dependencies. |
||
48 | * |
||
49 | * @return \Youshido\GraphQL\Field\FieldInterface[] |
||
50 | * The list of fields. |
||
51 | */ |
||
52 | View Code Duplication | protected function buildFields(PluggableSchemaBuilderInterface $schemaBuilder) { |
|
75 | |||
76 | /** |
||
77 | * Build the field type. |
||
78 | * |
||
79 | * @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
||
80 | * Instance of the schema manager to resolve dependencies. |
||
81 | * @param array|string $field |
||
82 | * The field definition array or type name. |
||
83 | * |
||
84 | * @return \Youshido\GraphQL\Type\TypeInterface |
||
85 | * The type object. |
||
86 | */ |
||
87 | View Code Duplication | protected function buildFieldType(PluggableSchemaBuilderInterface $schemaBuilder, $field) { |
|
97 | } |
||
98 |
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.