Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
9 / 10
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Type_Literal
90.00% covered (success)
90.00%
9 / 10
80.00% covered (warning)
80.00%
4 / 5
6.04
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 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;
6
7class Type_Literal implements Parser {
8    /**
9     * @var mixed
10     */
11    private $literal_value;
12
13    public function __construct( $literal_value ) {
14        $this->literal_value = $literal_value;
15    }
16
17    public function parse( $_value, $_context ) {
18        return $this->literal_value;
19    }
20
21    public function __toString() {
22        if ( is_string( $this->literal_value ) ) {
23            return 'literal_value("' . $this->literal_value . '")';
24        }
25        $type = gettype( $this->literal_value );
26        return "literal_value($type)";
27    }
28
29    #[\ReturnTypeWillChange]
30    public function jsonSerialize() {
31        return $this->schema();
32    }
33
34    public function schema() {
35        return array(
36            'type' => (string) $this,
37        );
38    }
39}