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

InterfacePluginBase::createInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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