StringType::coerce()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

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