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 | abstract class TypePluginBase extends PluginBase implements TypeSystemPluginInterface { |
||
14 | use CacheablePluginTrait; |
||
15 | use DescribablePluginTrait; |
||
16 | |||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | public static function createInstance(PluggableSchemaBuilder $builder, $definition, $id) { |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | View Code Duplication | public function getDefinition() { |
|
60 | |||
61 | /** |
||
62 | * @param $definition |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | protected function buildInterfaces($definition) { |
||
69 | |||
70 | /** |
||
71 | * Checks whether this type applies to a given object. |
||
72 | * |
||
73 | * @param mixed $object |
||
74 | * The object to check against. |
||
75 | * @param mixed $context |
||
76 | * The execution context. |
||
77 | * @param \GraphQL\Type\Definition\ResolveInfo $info |
||
78 | * The resolve info object. |
||
79 | * |
||
80 | * @return null|bool |
||
81 | * TRUE if this type applies to the given object or FALSE if it doesn't. |
||
82 | */ |
||
83 | public function applies($object, $context, ResolveInfo $info) { |
||
86 | |||
87 | } |
||
88 |
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.