Completed
Pull Request — 8.x-3.x (#490)
by Sebastian
06:38
created

UndefinedType::isValidValue()   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\GraphQL\Type;
4
5
use Youshido\GraphQL\Type\Scalar\AbstractScalarType;
6
7
class UndefinedType extends AbstractScalarType {
8
9
  /**
10
   * {@inheritdoc}
11
   */
12
  public function getName() {
13
    return 'Undefined';
14
  }
15
16
  /**
17
   * {@inheritdoc}
18
   */
19
  public function serialize($value) {
20
    if (is_bool($value) || is_null($value) || is_scalar($value)) {
21
      return $value;
22
    }
23
24
    if (is_object($value) && method_exists($value, '__toString')) {
25
      return (string) $value;
26
    }
27
28
    if (is_array($value) || is_object($value)) {
29
      return json_encode($value);
30
    }
31
32
    return '';
33
  }
34
35
  /**
36
   * {@inheritdoc}
37
   */
38
  public function isValidValue($value) {
39
    return TRUE;
40
  }
41
42
}
43