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

ScalarPluginBase::createInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL\Scalars;
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\TypeSystemPluginInterface;
9
use GraphQL\Type\Definition\CustomScalarType;
10
11
abstract class ScalarPluginBase extends PluginBase implements TypeSystemPluginInterface {
12
  use CacheablePluginTrait;
13
14
  /**
15
   * {@inheritdoc}
16
   */
17
  public static function createInstance(PluggableSchemaBuilder $builder, $definition, $id) {
18
    $callable = ['GraphQL\Type\Definition\Type', strtolower($definition['name'])];
19
    if (is_callable($callable)) {
20
      return $callable();
21
    }
22
23
    return new CustomScalarType($definition);
24
  }
25
26
  /**
27
   * {@inheritdoc}
28
   */
29
  public function getDefinition() {
30
    return $this->getPluginDefinition();
31
  }
32
33
  /**
34
   * @param mixed $value
35
   */
36
  public static function serialize($value) {
37
    throw new \LogicException('Missing method.');
38
  }
39
40
  /**
41
   * @param mixed $value
42
   *
43
   * @return mixed
44
   */
45
  public static function parseValue($value) {
46
    throw new \LogicException('Missing method.');
47
  }
48
49
  /**
50
   * @param mixed $node
51
   *
52
   * @return mixed
53
   */
54
  public static function parseLiteral($node) {
55
    throw new \LogicException('Missing method.');
56
  }
57
58
}
59