Completed
Pull Request — 8.x-3.x (#686)
by Sebastian
01:48
created

MutationPluginBase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 36
loc 36
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 12 12 1
A getDefinition() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Drupal\Drupal\graphql\GraphQL\Utility\Plugin\GraphQL\Mutations;
4
5
use Drupal\Component\Plugin\PluginBase;
6
use Drupal\graphql\Plugin\MutationPluginInterface;
7
use Drupal\graphql\Plugin\MutationPluginManager;
8
use Drupal\graphql\Plugin\GraphQL\Traits\ArgumentAwarePluginTrait;
9
use Drupal\graphql\Plugin\GraphQL\Traits\DeprecatablePluginTrait;
10
use Drupal\graphql\Plugin\GraphQL\Traits\DescribablePluginTrait;
11
use Drupal\graphql\Plugin\GraphQL\Traits\TypedPluginTrait;
12
use Drupal\graphql\Plugin\SchemaBuilderInterface;
13
14 View Code Duplication
abstract class MutationPluginBase extends PluginBase implements MutationPluginInterface {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
15
  use TypedPluginTrait;
16
  use DescribablePluginTrait;
17
  use ArgumentAwarePluginTrait;
18
  use DeprecatablePluginTrait;
19
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public static function createInstance(SchemaBuilderInterface $builder, MutationPluginManager $manager, $definition, $id) {
24
    return [
25
      'description' => $definition['description'],
26
      'deprecationReason' => $definition['deprecationReason'],
27
      'type' => $builder->processType($definition['type']),
28
      'args' => $builder->processArguments($definition['args']),
29
      'resolve' => function ($value, $args, $context, $info) use ($manager, $id) {
30
        $instance = $manager->getInstance(['id' => $id]);
31
        return call_user_func_array([$instance, 'resolve'], [$value, $args, $context, $info]);
32
      },
33
    ];
34
  }
35
36
  /**
37
   * {@inheritdoc}
38
   */
39
  public function getDefinition() {
40
    $definition = $this->getPluginDefinition();
41
42
    return [
43
      'type' => $this->buildType($definition),
44
      'description' => $this->buildDescription($definition),
45
      'args' => $this->buildArguments($definition),
46
      'deprecationReason' => $this->buildDeprecationReason($definition),
47
    ];
48
  }
49
}
50