Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#288)
by Jérémiah
19:40
created

CustomScalarType   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 73
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A parseValue() 0 4 1
A parseLiteral() 0 4 1
A __construct() 0 7 3
A call() 0 8 2
A assertValid() 0 18 2
A loadScalarType() 0 10 3
1
<?php
2
3
namespace Overblog\GraphQLBundle\Definition\Type;
4
5
use GraphQL\Type\Definition\CustomScalarType as BaseCustomScalarType;
6
use GraphQL\Type\Definition\ScalarType;
7
use GraphQL\Utils\Utils;
8
9
class CustomScalarType extends BaseCustomScalarType
10
{
11 24
    public function __construct(array $config = [])
12
    {
13 24
        $config['name'] = isset($config['name']) ? $config['name'] : uniqid('CustomScalar');
14 24
        parent::__construct($config);
15
16 24
        $this->config['scalarType'] = isset($this->config['scalarType']) ? $this->config['scalarType'] : null;
17 24
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 8
    public function serialize($value)
23
    {
24 8
        return $this->call('serialize', $value);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 7
    public function parseValue($value)
31
    {
32 7
        return $this->call('parseValue', $value);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 5
    public function parseLiteral(/* GraphQL\Language\AST\ValueNode */ $valueNode)
39
    {
40 5
        return $this->call('parseLiteral', $valueNode);
41
    }
42
43 12
    private function call($type, $value)
44
    {
45 12
        if (isset($this->config['scalarType'])) {
46 9
            return call_user_func([$this->loadScalarType(), $type], $value);
47
        } else {
48 3
            return parent::$type($value);
49
        }
50
    }
51
52 20
    public function assertValid()
53
    {
54 20
        if (isset($this->config['scalarType'])) {
55 17
            $scalarType = $this->loadScalarType();
56
57 17
            Utils::invariant(
58 17
                $scalarType instanceof ScalarType,
59 17
                sprintf(
60 17
                    '%s must provide a valid "scalarType" instance of %s but got: %s',
61 17
                    $this->name,
62 17
                    ScalarType::class,
63 17
                    Utils::printSafe($scalarType)
64
                )
65
            );
66
        } else {
67 3
            parent::assertValid();
68
        }
69 15
    }
70
71 18
    private function loadScalarType()
72
    {
73 18
        if ($this->config['scalarType'] instanceof ScalarType) {
74 9
            return $this->config['scalarType'];
75 18
        } elseif (is_callable($this->config['scalarType'])) {
76 16
            return $this->config['scalarType'] = $this->config['scalarType']();
77
        } else {
78 2
            return $this->config['scalarType'];
79
        }
80
    }
81
}
82