Completed
Push — master ( d6a52e...9b4e23 )
by Michael
02:57
created

DisplayStatisticsController::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 9
cp 0
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
	public function __construct(StatsJsonView $view)
35
	{
36
		$this->view = $view;
37
	}
38
39
	/**
40
	 * Execute the controller.
41
	 *
42
	 * @return  boolean
43
	 */
44
	public function execute()
45
	{
46
		// Check if we are allowed to receive the raw data
47
		$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
		$source = $this->getInput()->getString('source', '');
51
52
		$this->view->isAuthorizedRaw($authorizedRaw);
53
		$this->view->setSource($source);
54
55
		$this->getApplication()->setBody($this->view->render());
56
57
		return true;
58
	}
59
}
60