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_String
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_String implements Parser {
9
10    public function parse( $value, $_context ) {
11
12        if ( ! is_scalar( $value ) ) {
13            throw new Schema_Error( 'Expected a string, received ' . gettype( $value ), $value );
14        }
15
16        return (string) $value;
17    }
18
19    public function __toString() {
20        return 'string';
21    }
22
23    #[\ReturnTypeWillChange]
24    public function jsonSerialize() {
25        return $this->schema();
26    }
27
28    public function schema() {
29        return array(
30            'type' => (string) $this,
31        );
32    }
33}