Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
4 / 8 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Type_Float | |
50.00% |
4 / 8 |
|
50.00% |
2 / 4 |
8.12 | |
0.00% |
0 / 1 |
| parse | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| schema | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack\Schema\Types; |
| 4 | |
| 5 | use Automattic\Jetpack\Schema\Parser; |
| 6 | use Automattic\Jetpack\Schema\Schema_Error; |
| 7 | |
| 8 | class Type_Float implements Parser { |
| 9 | public function parse( $value, $_context ) { |
| 10 | if ( ! is_numeric( $value ) ) { |
| 11 | throw new Schema_Error( 'Invalid number', $value ); |
| 12 | } |
| 13 | return (float) $value; |
| 14 | } |
| 15 | public function __toString() { |
| 16 | return 'float'; |
| 17 | } |
| 18 | |
| 19 | #[\ReturnTypeWillChange] |
| 20 | public function jsonSerialize() { |
| 21 | return $this->schema(); |
| 22 | } |
| 23 | public function schema() { |
| 24 | return array( |
| 25 | 'type' => (string) $this, |
| 26 | ); |
| 27 | } |
| 28 | } |