Passed
Push — master ( e53b80...bdf164 )
by Brian
04:19
created

GetPaid_Reports_Report   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 68
c 2
b 0
f 1
dl 0
loc 135
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A display() 0 13 1
A __construct() 0 22 1
A display_left() 0 3 1
A get_download_url() 0 12 1
A display_right() 0 41 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 array
17
	 */
18
	public $views;
19
20
	/**
21
	 * Class constructor.
22
	 *
23
	 */
24
	public function __construct() {
25
26
		$this->views        = array(
27
28
            'items'     => array(
29
				'label' => __( 'Items', 'invoicing' ),
30
				'class' => 'GetPaid_Reports_Report_Items',
31
			),
32
33
			'gateways'  => array(
34
				'label' => __( 'Payment Methods', 'invoicing' ),
35
				'class' => 'GetPaid_Reports_Report_Gateways',
36
			),
37
38
			'discounts'  => array(
39
				'label' => __( 'Discount Codes', 'invoicing' ),
40
				'class' => 'GetPaid_Reports_Report_Discounts',
41
			),
42
43
        );
44
45
		$this->views        = apply_filters( 'wpinv_report_views', $this->views );
46
47
	}
48
49
	/**
50
	 * Displays the reports tab.
51
	 *
52
	 */
53
	public function display() {
54
		?>
55
56
		<div class="mt-4" style="max-width: 1200px;">
57
58
			<div class="row">
59
				<div class="col-12 col-md-8">
60
					<?php echo $this->display_left(); ?>
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->display_left() targeting GetPaid_Reports_Report::display_left() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
61
				</div>
62
63
				<div class="col-12 col-md-4">
64
					<?php echo $this->display_right(); ?>
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->display_right() targeting GetPaid_Reports_Report::display_right() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
65
				</div>
66
			</div>
67
68
		</div>
69
70
		<?php
71
72
	}
73
74
	/**
75
	 * Displays the left side.
76
	 *
77
	 */
78
	public function display_left() {
79
		$earnings = new GetPaid_Reports_Report_Earnings();
80
		$earnings->display();
81
	}
82
83
	/**
84
	 * Retrieves the download url.
85
	 *
86
	 */
87
	public function get_download_url( $graph, $file_type) {
88
89
		return wp_nonce_url(
90
			add_query_arg(
91
				array(
92
					'getpaid-admin-action' => 'download_graph',
93
					'file_type'            => urlencode( $file_type ),
94
					'graph'                => urlencode( $graph ),
95
				)
96
			),
97
			'getpaid-nonce',
98
			'getpaid-nonce'
99
		);
100
101
	}
102
103
	/**
104
	 * Displays the right side.
105
	 *
106
	 */
107
	public function display_right() {
108
109
		?>
110
111
			<?php foreach ( $this->views as $key => $view ) : ?>
112
				<div class="row mb-4">
113
					<div class="col-12">
114
						<div class="card m-0 p-0" style="max-width:100%">
115
							<div class="card-header">
116
								<div class="row">
117
									<div class="col-9">
118
										<strong><?php echo $view['label']; ?></strong>
119
									</div>
120
									<div class="col-3">
121
										<a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>">
122
											<i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i>
123
											<span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span>
124
										</a>
125
										<a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>">
126
											<i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i>
127
											<span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span>
128
										</a>
129
										<a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>">
130
											<i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i>
131
											<span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span>
132
										</a>
133
									</div>
134
								</div>
135
							</div>
136
							<div class="card-body">
137
								<?php
138
									$class = $view['class'];
139
									$class = new $class();
140
									$class->display_stats();
141
								?>
142
							</div>
143
						</div>
144
					</div>
145
				</div>
146
			<?php endforeach; ?>
147
148
		<?php
149
150
	}
151
152
}
153