StringType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A coerce() 0 8 3
A coerceLiteral() 0 4 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