Total Complexity | 13 |
Total Lines | 69 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
23 | class FloatType extends ScalarType |
||
24 | { |
||
25 | /** @var string */ |
||
26 | public $name = Type::FLOAT; |
||
27 | |||
28 | /** @var string */ |
||
29 | public $description = |
||
30 | 'The `Float` scalar type represents signed double-precision fractional |
||
31 | values as specified by |
||
32 | [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). '; |
||
33 | |||
34 | /** |
||
35 | * @param mixed $value |
||
36 | * |
||
37 | * @return float|null |
||
38 | * |
||
39 | * @throws Error |
||
40 | */ |
||
41 | 8 | public function serialize($value) |
|
42 | { |
||
43 | 8 | $float = is_numeric($value) || is_bool($value) ? floatval($value) : null; |
|
44 | |||
45 | 8 | if ($float === null || ! is_finite($float)) { |
|
46 | 5 | throw new Error( |
|
47 | 'Float cannot represent non numeric value: ' . |
||
48 | 5 | Utils::printSafe($value) |
|
49 | ); |
||
50 | } |
||
51 | |||
52 | 3 | return $float; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param mixed $value |
||
57 | * |
||
58 | * @return float|null |
||
59 | * |
||
60 | * @throws Error |
||
61 | */ |
||
62 | 10 | public function parseValue($value) |
|
63 | { |
||
64 | 10 | $float = is_float($value) || is_int($value) ? floatval($value) : null; |
|
65 | |||
66 | 10 | if ($float === null || ! is_finite($float)) { |
|
67 | 6 | throw new Error( |
|
68 | 'Float cannot represent non numeric value: ' . |
||
69 | 6 | Utils::printSafe($value) |
|
70 | ); |
||
71 | } |
||
72 | |||
73 | 4 | return $float; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param Node $valueNode |
||
78 | * @param mixed[]|null $variables |
||
79 | * |
||
80 | * @return float|null |
||
81 | * |
||
82 | * @throws Exception |
||
83 | */ |
||
84 | 8 | public function parseLiteral($valueNode, ?array $variables = null) |
|
92 | } |
||
93 | } |
||
94 |