Completed
Pull Request — 8.x-3.x (#525)
by Sebastian
04:20 queued 01:58
created

ScalarPluginBase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 10 2
A getDefinition() 0 3 1
A serialize() 0 3 1
A parseValue() 0 3 1
A parseLiteral() 0 3 1
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([
24
25
    ] + $definition);
26
  }
27
28
  /**
29
   * {@inheritdoc}
30
   */
31
  public function getDefinition() {
32
    return $this->getPluginDefinition();
33
  }
34
35
  /**
36
   * @param mixed $value
37
   */
38
  public static function serialize($value) {
39
    throw new \LogicException('Missing method.');
40
  }
41
42
  /**
43
   * @param mixed $value
44
   *
45
   * @return mixed
46
   */
47
  public static function parseValue($value) {
48
    throw new \LogicException('Missing method.');
49
  }
50
51
  /**
52
   * @param mixed $node
53
   *
54
   * @return mixed
55
   */
56
  public static function parseLiteral($node) {
57
    throw new \LogicException('Missing method.');
58
  }
59
60
}
61