Completed
Pull Request — develop (#1282)
by David
07:16 queued 04:07
created

Sync_Background_Process_Wpjson_Endpoint   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A rest_api_init() 0 33 1
1
<?php
2
3
namespace Wordlift\Dataset\Background;
4
5
use WP_REST_Server;
6
7
class Sync_Background_Process_Wpjson_Endpoint {
8
9
	/**
10
	 * @var Sync_Background_Process
11
	 */
12
	private $sync_background_process;
13
14
	/**
15
	 * Sync_Background_Process_Wpjson_Endpoint constructor.
16
	 *
17
	 * @param Sync_Background_Process $sync_background_process
18
	 */
19
	function __construct( $sync_background_process ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
21
		add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
22
23
		$this->sync_background_process = $sync_background_process;
24
25
	}
26
27
	function rest_api_init() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
29
		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
30
			'methods'             => WP_REST_Server::CREATABLE,
31
			'callback'            => array( $this->sync_background_process, 'start' ),
32
			'permission_callback' => function () {
33
				$user = wp_get_current_user();
34
35
				return in_array( 'administrator', (array) $user->roles );
36
			}
37
		) );
38
39
		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
40
			'methods'             => WP_REST_Server::READABLE,
41
			'callback'            => array( $this->sync_background_process, 'get_info' ),
42
			'permission_callback' => function () {
43
				$user = wp_get_current_user();
44
45
				return in_array( 'administrator', (array) $user->roles );
46
			}
47
		) );
48
49
		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
50
			'methods'             => WP_REST_Server::DELETABLE,
51
			'callback'            => array( $this->sync_background_process, 'stop' ),
52
			'permission_callback' => function () {
53
				$user = wp_get_current_user();
54
55
				return in_array( 'administrator', (array) $user->roles );
56
			}
57
		) );
58
59
	}
60
61
}
62