Completed
Pull Request — master (#134)
by Christoffer
04:40 queued 02:00
created

StringCoercer::coerce()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 5
nop 1
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