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

Any::parseLiteral()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
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 = "any",
10
 *   name = "Any",
11
 *   type = "any"
12
 * )
13
 */
14
class Any 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_scalar($value)) {
21
      return $value;
22
    }
23
24
    if (is_array($value)) {
25
      return json_encode($value);
26
    }
27
28
    if (is_object($value) && method_exists($value, '__toString')) {
29
      return (string) $value;
30
    }
31
32
    return '';
33
  }
34
35
  /**
36
   * {@inheritdoc}
37
   */
38
  public static function parseValue($value) {
39
    return $value;
40
  }
41
42
  /**
43
   * {@inheritdoc}
44
   */
45
  public static function parseLiteral($ast) {
46
    return $ast->value;
47
  }
48
49
}
50