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