ReportsController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 12 3
1
<?php
2
/**
3
 * This file contains only a single class.
4
 *
5
 * @file
6
 * @package Tabulate
7
 */
8
9
namespace WordPress\Tabulate\Controllers;
10
11
use \WordPress\Tabulate\DB\Database;
12
use \WordPress\Tabulate\DB\Reports;
13
14
/**
15
 * The reports controller is responsible for displaying reports.
16
 * Editing of reports is done in the usual Tabulate fashion.
17
 */
18
class ReportsController extends ControllerBase {
19
20
	/**
21
	 * View a report.
22
	 *
23
	 * @param string[] $args The request arguments.
24
	 * @return type
25
	 */
26
	public function index( $args ) {
27
		$db = new Database( $this->wpdb );
28
		$id = isset( $args['id'] ) ? $args['id'] : Reports::DEFAULT_REPORT_ID;
29
		$reports = new Reports( $db );
30
		$template = $reports->get_template( $id );
31
		$out = $template->render();
32
		if ( $template->file_extension ) {
33
			$this->send_file( $template->file_extension, $template->mime_type, $out, $template->title );
34
		} else {
35
			return $out;
36
		}
37
	}
38
}
39