Completed
Pull Request — master (#134)
by Christoffer
02:39
created

StringCoercer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B coerce() 0 19 5
1
<?php
2
3
namespace Digia\GraphQL\Type\Coercer;
4
5
use Digia\GraphQL\Error\InvalidTypeException;
6
7
class StringCoercer extends AbstractCoercer
8
{
9
    /**
10
     * @inheritdoc
11
     */
12
    public function coerce($value)
13
    {
14
        if ($value === null) {
15
            return 'null';
16
        }
17
18
        if ($value === true) {
19
            return 'true';
20
        }
21
22
        if ($value === false) {
23
            return 'false';
24
        }
25
26
        if (!\is_scalar($value)) {
27
            throw new InvalidTypeException('String cannot represent a non-scalar value');
28
        }
29
30
        return (string)$value;
31
    }
32
}
33