Passed
Push — hotfix/fix-counts ( 4b43d1...cc9e05 )
by Paul
03:52
created

RestReviewController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
eloc 17
c 3
b 0
f 2
dl 0
loc 55
ccs 0
cts 33
cp 0
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A register_routes() 0 8 1
A getReviews() 0 4 1
A createReview() 0 4 1
A getReviewTypes() 0 10 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers;
4
5
use GeminiLabs\SiteReviews\Application;
6
use WP_Error;
7
use WP_REST_Post_Meta_Fields;
8
use WP_REST_Posts_Controller as RestController;
9
use WP_REST_Request as Request;
10
use WP_REST_Response as Response;
11
use WP_REST_Server as Server;
12
13
class RestReviewController extends RestController
14
{
15
    public function __construct()
16
    {
17
        $this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE);
18
        $this->namespace = Application::ID.'/v1';
19
        $this->post_type = Application::POST_TYPE;
20
        $this->rest_base = 'reviews';
21
    }
22
23
    /**
24
     * @return void
25
     */
26
    public function register_routes()
27
    {
28
        // register_rest_route( $this->namespace, '/'.$this->rest_base, [
29
        //  ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE],
30
        //  ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE],
31
        // ]);
32
        register_rest_route($this->namespace, '/types', [
33
            ['callback' => [$this, 'getReviewTypes'], 'methods' => Server::READABLE],
34
        ]);
35
    }
36
37
    /**
38
     * @return WP_Error|Response|mixed
39
     */
40
    public function createReview()
41
    {
42
        $response = [];
43
        return rest_ensure_response($response);
44
    }
45
46
    /**
47
     * @return WP_Error|Response|mixed
48
     */
49
    public function getReviews()
50
    {
51
        $response = [];
52
        return rest_ensure_response($response);
53
    }
54
55
    /**
56
     * @return WP_Error|Response|mixed
57
     */
58
    public function getReviewTypes()
59
    {
60
        $response = [];
61
        foreach (glsr()->reviewTypes as $slug => $name) {
62
            $response[] = [
63
                'name' => $name,
64
                'slug' => $slug,
65
            ];
66
        }
67
        return rest_ensure_response($response);
68
    }
69
}
70