StringType::coerceLiteral()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
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\StringValue;
7
use Fubhy\GraphQL\Type\Definition\Types\ScalarType;
8
9
class StringType extends ScalarType
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name = 'String';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 231
    public function coerce($value)
20
    {
21 231
        if (is_bool($value)) {
22 9
            return $value ? 'true' : 'false';
23
        }
24
25 225
        return (string) $value;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 72
    public function coerceLiteral(Node $node)
32
    {
33 72
        return $node instanceof StringValue ? $node->get('value') : NULL;
34
    }
35
}
36