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 |
||
9 | View Code Duplication | class MutationPluginManager extends DefaultPluginManager { |
|
|
|||
10 | |||
11 | /** |
||
12 | * Static cache of plugin instances. |
||
13 | * |
||
14 | * @var \Drupal\graphql\Plugin\MutationPluginInterface[] |
||
15 | */ |
||
16 | protected $instances; |
||
17 | |||
18 | /** |
||
19 | * FieldPluginManager constructor. |
||
20 | * |
||
21 | * @param bool|string $pluginSubdirectory |
||
22 | * The plugin's subdirectory. |
||
23 | * @param \Traversable $namespaces |
||
24 | * An object that implements \Traversable which contains the root paths |
||
25 | * keyed by the corresponding namespace to look for plugin implementations. |
||
26 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler |
||
27 | * The module handler. |
||
28 | * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend |
||
29 | * The cache backend. |
||
30 | * @param string|null $pluginInterface |
||
31 | * The interface each plugin should implement. |
||
32 | * @param string $pluginAnnotationName |
||
33 | * The name of the annotation that contains the plugin definition. |
||
34 | */ |
||
35 | public function __construct( |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function getInstance(array $options) { |
||
66 | |||
67 | } |
||
68 |
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.