Passed
Pull Request — master (#444)
by Brian
05:33
created

GetPaid_Reports_Report   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 45
c 1
b 0
f 0
dl 0
loc 95
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A display() 0 32 1
A display_current_view() 0 18 2
1
<?php
2
/**
3
 * Contains the class that displays a single report.
4
 *
5
 *
6
 */
7
8
defined( 'ABSPATH' ) || exit;
9
10
/**
11
 * GetPaid_Reports_Report Class.
12
 */
13
class GetPaid_Reports_Report {
14
15
	/**
16
	 * @var string
17
	 */
18
	public $current_view;
19
20
	/**
21
	 * @var array
22
	 */
23
	public $views;
24
25
	/**
26
	 * Class constructor.
27
	 *
28
	 */
29
	public function __construct() {
30
31
		$this->views        = array(
32
            'earnings'   => __( 'Earnings', 'invoicing' ),
33
            'items'      => __( 'Items', 'invoicing' ),
34
            'gateways'   => __( 'Payment Methods', 'invoicing' ),
35
            'taxes'      => __( 'Taxes', 'invoicing' ),
36
        );
37
38
		$this->views        = apply_filters( 'wpinv_report_views', $this->views );
39
		$this->current_view = 'earnings';
40
41
		if ( isset( $_GET['view'] ) && array_key_exists( $_GET['view'], $this->views ) ) {
42
			$this->current_view = sanitize_text_field( $_GET['view'] );
43
		}
44
45
	}
46
47
	/**
48
	 * Displays the reports tab.
49
	 *
50
	 */
51
	public function display() {
52
		?>
53
54
			<form method="get" class="d-block mt-4 getpaid-change-view">
55
56
				<?php
57
58
					getpaid_hidden_field( 'page', 'wpinv-reports' );
59
					getpaid_hidden_field( 'tab', 'reports' );
60
61
					echo aui()->select(
62
						array(
63
							'name'        => 'view',
64
							'id'          => 'view' . uniqid( '_' ),
65
							'placeholder' => __( 'Select a report', 'invoicing' ),
66
							'label'       => __( 'Report Type', 'invoicing' ),
67
							'options'     => $this->views,
68
							'no_wrap'     => true,
69
						)
70
					);
71
72
					echo "&nbsp;";
73
74
					getpaid_submit_field( __( 'Show', 'invoicing' ), '', 'btn-secondary' );
75
76
				?>
77
78
	        </form>
79
80
		<?php
81
82
		$this->display_current_view();
83
84
	}
85
86
	/**
87
	 * Displays a single reports view.
88
	 *
89
	 */
90
	public function display_current_view() {
91
92
		$default_classes = array(
93
			'earnings'   => 'GetPaid_Reports_Report_Earnings',
94
			'items'      => 'GetPaid_Reports_Report_Items',
95
			'gateways'   => 'GetPaid_Reports_Report_Gateways',
96
			'taxes'      => 'GetPaid_Reports_Report_Taxes',
97
		);
98
		$class = 'GetPaid_Reports_Report_' . ucfirst( $this->current_view );
0 ignored issues
show
Unused Code introduced by
The assignment to $class is dead and can be removed.
Loading history...
99
100
		if ( isset( $default_classes[ $this->current_view ] ) ) {
101
102
			$class = new $default_classes[ $this->current_view ]();
103
			$class->display();
104
105
		}
106
107
		do_action( 'wpinv_reports_tab' . $this->current_view );
108
109
	}
110
111
}
112