IdType::coerce()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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