Passed
Pull Request — master (#444)
by Brian
10:32
created

GetPaid_Reports::display_reports_page()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 42
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 28
c 2
b 0
f 0
nc 12
nop 0
dl 0
loc 42
rs 9.1608
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
			wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
87
			wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
88
89
	}
90
91
	/**
92
	 * Retrieves reports page tabs.
93
	 *
94
	 * @return array
95
	 */
96
	public function get_tabs() {
97
98
		$tabs = array(
99
			'reports' => __( 'Reports', 'invoicing' ),
100
			'export'  => __( 'Export', 'invoicing' ),
101
		);
102
103
		return apply_filters( 'getpaid_report_tabs', $tabs );
104
	}
105
106
	/**
107
	 * Displays the reports tab.
108
	 *
109
	 */
110
	public function display_reports_tab() {
111
112
		$reports = new GetPaid_Reports_Report();
113
		$reports->display();
114
115
	}
116
117
	/**
118
	 * Displays the exports tab.
119
	 *
120
	 */
121
	public function display_exports_tab() {
122
123
		$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...
124
		$exports->display();
125
126
	}
127
128
}
129