Completed
Push — master ( 9a3a3c...24148b )
by Michael
14s
created

DisplayStatisticsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Joomla! Statistics Server
4
 *
5
 * @copyright  Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
6
 * @license    http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
7
 */
8
9
namespace Joomla\StatsServer\Controllers;
10
11
use Joomla\Controller\AbstractController;
12
use Joomla\StatsServer\Views\Stats\StatsJsonView;
13
14
/**
15
 * Controller for displaying submitted statistics data.
16
 *
17
 * @method         \Joomla\Application\WebApplication  getApplication()  Get the application object.
18
 * @property-read  \Joomla\Application\WebApplication  $app              Application object
19
 */
20
class DisplayStatisticsController extends AbstractController
21
{
22
	/**
23
	 * JSON view for displaying the statistics.
24
	 *
25
	 * @var  StatsJsonView
26
	 */
27
	private $view;
28
29
	/**
30
	 * Constructor.
31
	 *
32
	 * @param   StatsJsonView  $view  JSON view for displaying the statistics.
33
	 */
34 3
	public function __construct(StatsJsonView $view)
35
	{
36 3
		$this->view = $view;
37 3
	}
38
39
	/**
40
	 * Execute the controller.
41
	 *
42
	 * @return  boolean
43
	 */
44 3
	public function execute()
45
	{
46
		// Check if we are allowed to receive the raw data
47 3
		$authorizedRaw = $this->getInput()->server->getString('HTTP_JOOMLA_RAW', 'fail') === $this->getApplication()->get('stats.rawdata', false);
48
49
		// Check if a single data source is requested
50 3
		$source = $this->getInput()->getString('source', '');
51
52 3
		$this->view->isAuthorizedRaw($authorizedRaw);
53 3
		$this->view->setSource($source);
54
55 3
		$this->getApplication()->setBody($this->view->render());
56
57 3
		return true;
58
	}
59
}
60