Completed
Pull Request — 8.x-3.x (#524)
by Sebastian
03:35
created

MutationPluginBase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 46.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 21
loc 45
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getDefinition() 21 21 5
A isSecure() 0 3 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\graphql\Plugin\GraphQL\Mutations;
4
5
use Drupal\Component\Plugin\PluginBase;
6
use Drupal\graphql\GraphQL\Field\Field;
7
use Drupal\graphql\GraphQL\SecureFieldInterface;
8
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface;
9
use Drupal\graphql\Plugin\GraphQL\Traits\ArgumentAwarePluginTrait;
10
use Drupal\graphql\Plugin\GraphQL\Traits\CacheablePluginTrait;
11
use Drupal\graphql\Plugin\GraphQL\Traits\NamedPluginTrait;
12
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface;
13
14
/**
15
 * Base class for graphql mutation plugins.
16
 */
17
abstract class MutationPluginBase extends PluginBase implements TypeSystemPluginInterface, SecureFieldInterface {
18
  use CacheablePluginTrait;
19
  use NamedPluginTrait;
20
  use ArgumentAwarePluginTrait;
21
22
  /**
23
   * The field instance.
24
   *
25
   * @var \Drupal\graphql\GraphQL\Field\Field
26
   */
27
  protected $definition;
28
29
  /**
30
   * {@inheritdoc}
31
   */
32 View Code Duplication
  public function getDefinition(PluggableSchemaBuilderInterface $schemaBuilder) {
0 ignored issues
show
Duplication introduced by
This method 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...
33
    if (!isset($this->definition)) {
34
      $definition = $this->getPluginDefinition();
35
36
      if ($type = $this->buildType($schemaBuilder)) {
37
        $this->definition = new Field($this, $schemaBuilder, [
38
          'name' => $this->buildName(),
39
          'description' => $this->buildDescription(),
40
          'type' => $type,
41
          'isDeprecated' => !empty($definition['deprecated']),
42
          'deprecationReason' => !empty($definition['deprecated']) ? !empty($definition['deprecated']) : '',
43
        ]);
44
45
        if ($args = $this->buildArguments($schemaBuilder)) {
46
          $this->definition->addArguments($args);
47
        }
48
      }
49
    }
50
51
    return $this->definition;
52
  }
53
54
  /**
55
   * {@inheritdoc}
56
   */
57
  public function isSecure() {
58
    return TRUE;
59
  }
60
61
}
62