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

AnyType   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
B serialize() 0 15 5
A isValidValue() 0 3 1
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Type\Scalars;
4
5
use Symfony\Component\HttpFoundation\File\UploadedFile;
6
use Youshido\GraphQL\Type\Scalar\AbstractScalarType;
7
8
class AnyType extends AbstractScalarType {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  public function getName() {
14
    return 'Any';
15
  }
16
17
  /**
18
   * {@inheritdoc}
19
   */
20
  public function serialize($value) {
21
    if (is_scalar($value)) {
22
      return $value;
23
    }
24
25
    if (is_array($value)) {
26
      return json_encode($value);
27
    }
28
29
    if (is_object($value) && method_exists($value, '__toString')) {
30
      return (string) $value;
31
    }
32
33
    return '';
34
  }
35
36
  /**
37
   * {@inheritdoc}
38
   */
39
  public function isValidValue($value) {
40
    return TRUE;
41
  }
42
43
}
44