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

Map::serialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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