Completed
Push — develop ( a6c8bc...e67402 )
by David
07:37
created

Wordlift_Sample_Data_Ajax_Adapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 12 1
A delete() 0 13 1
1
<?php
2
/**
3
 * Ajax Adapters: Sample Data Ajax Adapter.
4
 *
5
 * Provides end-points to call the {@link Wordlift_Sample_Data_Service} instance,
6
 * thus enabling loading sample data with a http call.
7
 *
8
 * @since   3.12.0
9
 * @package Wordlift
10
 */
11
12
/**
13
 * Define the {@link Wordlift_Sample_Data_Ajax_Adapter} class.
14
 *
15
 * @since   3.12.0
16
 * @package Wordlift
17
 */
18
class Wordlift_Sample_Data_Ajax_Adapter {
19
20
	/**
21
	 * The {@link Wordlift_Sample_Data_Service} instance.
22
	 *
23
	 * @since  3.12.0
24
	 * @access private
25
	 * @var \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance.
26
	 */
27
	private $sample_data_service;
28
29
	/**
30
	 * Create a {@link Wordlift_Sample_Data_Ajax_Adapter} instance.
31
	 *
32
	 * @since 3.12.0
33
	 *
34
	 * @param \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance.
35
	 */
36
	function __construct( $sample_data_service ) {
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...
37
38
		$this->sample_data_service = $sample_data_service;
39
40
	}
41
42
	/**
43
	 * Handle the `wl_sample_data_create` ajax action.
44
	 *
45
	 * @since 3.12.0
46
	 */
47
	function create() {
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...
48
49
		// Clean any potential garbage before us.
50
		ob_clean();
51
52
		// Create the sample data.
53
		$this->sample_data_service->create();
54
55
		// Send success.
56
		wp_send_json_success();
57
58
	}
59
60
	function delete() {
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...
61
62
		// Clean any potential garbage before us.
63
		ob_clean();
64
65
		// Create the sample data.
66
		$this->sample_data_service->delete();
67
68
		// Send success.
69
		@header( 'Content-Disposition: inline' );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
70
		wp_send_json_success();
71
72
	}
73
74
}