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

FloatCoercer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A coerce() 0 11 4
1
<?php
2
3
namespace Digia\GraphQL\Type\Coercer;
4
5
use Digia\GraphQL\Error\InvalidTypeException;
6
7
class FloatCoercer extends AbstractCoercer
8
{
9
    /**
10
     * @inheritdoc
11
     */
12
    public function coerce($value)
13
    {
14
        if ($value === '') {
15
            throw new InvalidTypeException('Float cannot represent non numeric value: (empty string)');
16
        }
17
18
        if (\is_numeric($value) || \is_bool($value)) {
19
            return (float)$value;
20
        }
21
22
        throw new InvalidTypeException(\sprintf('Float cannot represent non numeric value: %s', $value));
23
    }
24
}
25