Completed
Pull Request — 8.x-3.x (#525)
by Philipp
02:10
created

InterfacePluginBase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 7 1
A getDefinition() 0 8 1
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL\Interfaces;
4
5
use Drupal\Component\Plugin\PluginBase;
6
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilder;
7
use Drupal\graphql\Plugin\GraphQL\Traits\CacheablePluginTrait;
8
use Drupal\graphql\Plugin\GraphQL\Traits\DescribablePluginTrait;
9
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface;
10
use GraphQL\Type\Definition\InterfaceType;
11
12
abstract class InterfacePluginBase extends PluginBase implements TypeSystemPluginInterface {
13
  use CacheablePluginTrait;
14
  use DescribablePluginTrait;
15
16
  /**
17
   * {@inheritdoc}
18
   */
19
  public static function createInstance(PluggableSchemaBuilder $builder, $definition, $id) {
20
    return new InterfaceType([
21
      'fields' => function () use ($builder, $definition) {
22
        return $builder->getFieldsByType($definition['name']);
23
      }
24
    ] + $definition);
25
  }
26
27
  /**
28
   * {@inheritdoc}
29
   */
30
  public function getDefinition() {
31
    $definition = $this->getPluginDefinition();
32
33
    return [
34
      'name' => $definition['name'],
35
      'description' => $this->buildDescription($definition),
36
    ];
37
  }
38
39
}
40