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

InterfaceType::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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