Passed
Push — master ( ae72bf...aa4919 )
by Christoffer
02:29
created

FloatCoercer::coerce()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 3
nop 1
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