IdType::coerceLiteral()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

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