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 |
||
| 10 | class Schema extends AbstractSchema { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * The corresponding plugin for this schema. |
||
| 14 | * |
||
| 15 | * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface |
||
| 16 | */ |
||
| 17 | protected $plugin; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Schema constructor. |
||
| 21 | * |
||
| 22 | * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface $plugin |
||
| 23 | * The corresponding plugin instance for this schema. |
||
| 24 | * @param array $config |
||
| 25 | * The schema configuration array. |
||
| 26 | */ |
||
| 27 | public function __construct(SchemaPluginInterface $plugin, array $config = []) { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Retrieves the schema's plugin instance. |
||
| 34 | * |
||
| 35 | * @return \Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface |
||
| 36 | * The schema plugin instance. |
||
| 37 | */ |
||
| 38 | public function getSchemaPlugin() { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | public function build(SchemaConfig $config) { |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function __sleep() { |
|
| 70 | |||
| 71 | } |
||
| 72 |
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.