Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
4 / 6
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
REST_API
66.67% covered (warning)
66.67%
4 / 6
66.67% covered (warning)
66.67%
2 / 3
5.93
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 register_rest_routes
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 register
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Automattic\Jetpack_Boost\REST_API;
4
5use Automattic\Jetpack_Boost\REST_API\Contracts\Endpoint;
6
7class REST_API {
8
9    /**
10     * @var Route[]
11     */
12    protected $routes = array();
13
14    /**
15     * @param Endpoint[] $routes
16     */
17    public function __construct( $routes ) {
18        foreach ( $routes as $route_class ) {
19            $this->routes[] = new Route( $route_class );
20        }
21    }
22
23    public function register_rest_routes() {
24        foreach ( $this->routes as $route ) {
25            $route->register_rest_route();
26        }
27    }
28
29    /**
30     * @param Endpoint|Endpoint[]|string $endpoints
31     *
32     * @return void
33     */
34    public static function register( $endpoints ) {
35        // If endpoints are passed as a string,
36        // (array) will convert it to an array.
37        $rest_api = new REST_API( (array) $endpoints );
38        add_action( 'rest_api_init', array( $rest_api, 'register_rest_routes' ) );
39    }
40}