IdType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 27
ccs 3
cts 6
cp 0.5
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A coerce() 0 4 1
A coerceLiteral() 0 8 3
1
<?php
2
3
namespace Fubhy\GraphQL\Type\Definition\Types\Scalars;
4
5
use Fubhy\GraphQL\Language\Node;
6
use Fubhy\GraphQL\Language\Node\IntValue;
7
use Fubhy\GraphQL\Language\Node\StringValue;
8
use Fubhy\GraphQL\Type\Definition\Types\ScalarType;
9
10
class IdType extends ScalarType
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $name = 'Id';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function coerce($value)
21
    {
22
        return (string) $value;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 3
    public function coerceLiteral(Node $node)
29
    {
30 3
        if ($node instanceof StringValue || $node instanceof IntValue) {
31 3
            return $node->get('value');
32
        }
33
34
        return NULL;
35
    }
36
}
37