Completed
Push — 8.x-3.x ( e67c0e...2e01b0 )
by Philipp
02:27
created

InterfaceType   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 19.61 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A registerType() 0 3 1
A resolveType() 10 10 3
A build() 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\GraphQL\Type;
4
5
use Drupal\graphql\GraphQL\CacheableEdgeInterface;
6
use Drupal\graphql\GraphQL\CacheableEdgeTrait;
7
use Drupal\graphql\Plugin\GraphQL\Interfaces\InterfacePluginBase;
8
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginReferenceInterface;
9
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginReferenceTrait;
10
use Youshido\GraphQL\Config\Object\InterfaceTypeConfig;
11
use Youshido\GraphQL\Execution\ResolveInfo;
12
use Youshido\GraphQL\Type\InterfaceType\AbstractInterfaceType;
13
14
class InterfaceType extends AbstractInterfaceType implements TypeSystemPluginReferenceInterface, CacheableEdgeInterface {
15
  use TypeSystemPluginReferenceTrait;
16
  use CacheableEdgeTrait;
17
18
  /**
19
   * List of types implementing this interface.
20
   *
21
   * @var \Drupal\graphql\GraphQL\Type\ObjectType[]
22
   */
23
  protected $types;
24
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function __construct(InterfacePluginBase $plugin, array $config = []) {
29
    $this->plugin = $plugin;
30
    $this->config = new InterfaceTypeConfig($config, $this, TRUE);
31
  }
32
33
  /**
34
   * Registers a type that implements this interface.
35
   *
36
   * @param \Drupal\graphql\GraphQL\Type\ObjectType $type
37
   *   The type to register on this interface.
38
   */
39
  public function registerType(ObjectType $type) {
40
    $this->types[$type->getName()] = $type;
41
  }
42
43
  /**
44
   * {@inheritdoc}
45
   */
46 View Code Duplication
  public function resolveType($object, ResolveInfo $info = NULL) {
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...
47
    /** @var \Drupal\graphql\GraphQL\Type\ObjectType $type */
48
    foreach ($this->types as $type) {
49
      if ($type->applies($object, $info)) {
50
        return $type;
51
      }
52
    }
53
54
    throw new \Exception(sprintf('Could not resolve type for interface %s.', $this->getName()));
55
  }
56
57
  /**
58
   * {@inheritdoc}
59
   */
60
  public function build($config) {
61
    // Nothing to do here.
62
  }
63
64
}
65