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

Map   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 7 2
A parseValue() 0 3 1
A parseLiteral() 0 3 1
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL\Scalars\TypedData;
4
5
use Drupal\graphql\Plugin\GraphQL\Scalars\ScalarPluginBase;
6
7
/**
8
 * @GraphQLScalar(
9
 *   id = "map",
10
 *   name = "Map",
11
 *   type = "map"
12
 * )
13
 */
14
class Map extends ScalarPluginBase {
0 ignored issues
show
Bug introduced by
There is one abstract method getPluginDefinition in this class; you could implement it, or declare this class as abstract.
Loading history...
15
16
  /**
17
   * {@inheritdoc}
18
   */
19
  public static function serialize($value) {
20
    if (is_array($value)) {
21
      return json_encode($value);
22
    }
23
24
    return NULL;
25
  }
26
27
  /**
28
   * {@inheritdoc}
29
   */
30
  public static function parseValue($value) {
31
    return json_decode($value, TRUE);
32
  }
33
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public static function parseLiteral($ast) {
38
    return json_decode($ast->value, TRUE);
39
  }
40
}
41