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

Any   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B serialize() 0 15 5
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\GraphQLString;
6
7
/**
8
 * @GraphQLScalar(
9
 *   id = "any",
10
 *   name = "Any",
11
 *   type = "any"
12
 * )
13
 */
14
class Any extends GraphQLString {
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