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

GetPaid_Reports::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Contains the reports class
4
 *
5
 *
6
 */
7
8
defined( 'ABSPATH' ) || exit;
9
10
/**
11
 * GetPaid_Reports Class.
12
 */
13
class GetPaid_Reports {
14
15
	/**
16
	 * Class constructor.
17
	 *
18
	 */
19
	public function __construct() {
20
		add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
		add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
		add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
	}
24
25
	/**
26
	 * Registers the reports page.
27
	 *
28
	 */
29
	public function register_reports_page() {
30
31
		add_submenu_page(
32
            'wpinv',
33
            __( 'Reports', 'invoicing' ),
34
            __( 'Reports', 'invoicing' ),
35
            wpinv_get_capability(),
36
            'wpinv-reports',
37
            array( $this, 'display_reports_page' )
38
		);
39
40
	}
41
42
	/**
43
	 * Displays the reports page.
44
	 *
45
	 */
46
	public function display_reports_page() {
47
48
		// Prepare variables.
49
		$tabs        = $this->get_tabs();
50
		$current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
51
		$current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
52
53
		// Display the current tab.
54
		?>
55
56
        <div class="wrap">
57
58
			<h1><?php echo sanitize_text_field( $tabs[ $current_tab ] ); ?></h1>
59
60
			<nav class="nav-tab-wrapper">
61
62
				<?php
63
					foreach( $tabs as $key => $label ) {
64
65
						$key   = sanitize_text_field( $key );
66
						$label = sanitize_text_field( $label );
67
						$class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
68
						$url   = esc_url(
69
							add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
70
						);
71
72
						echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
73
74
					}
75
				?>
76
77
			</nav>
78
79
			<div class="bsui <?php echo esc_attr( $current_tab ); ?>">
80
				<?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?>
81
			</div>
82
83
        </div>
84
		<?php
85
86
	}
87
88
	/**
89
	 * Retrieves reports page tabs.
90
	 *
91
	 * @return array
92
	 */
93
	public function get_tabs() {
94
95
		$tabs = array(
96
			'reports' => __( 'Reports', 'invoicing' ),
97
			'export'  => __( 'Export', 'invoicing' ),
98
		);
99
100
		return apply_filters( 'getpaid_report_tabs', $tabs );
101
	}
102
103
	/**
104
	 * Displays the reports tab.
105
	 *
106
	 */
107
	public function display_reports_tab() {
108
109
		$reports = new GetPaid_Reports_Report();
110
		$reports->display();
111
112
	}
113
114
	/**
115
	 * Displays the exports tab.
116
	 *
117
	 */
118
	public function display_exports_tab() {
119
120
		$exports = new GetPaid_Reports_Export();
0 ignored issues
show
Bug introduced by
The type GetPaid_Reports_Export was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
121
		$exports->display();
122
123
	}
124
125
}
126