Completed
Push — mysql_improvements ( 2e95ce...dedbef )
by Michael
03:52
created

SnapshotCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 72
ccs 0
cts 24
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 18 2
A getDescription() 0 4 1
A getTitle() 0 4 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\Commands;
10
11
use Joomla\Controller\AbstractController;
12
use Joomla\StatsServer\CommandInterface;
13
use Joomla\StatsServer\Views\Stats\StatsJsonView;
14
15
/**
16
 * Snapshot command
17
 *
18
 * @method         \Joomla\StatsServer\CliApplication  getApplication()  Get the application object.
19
 * @property-read  \Joomla\StatsServer\CliApplication  $app              Application object
20
 */
21
class SnapshotCommand extends AbstractController implements CommandInterface
22
{
23
	/**
24
	 * JSON view for displaying the statistics.
25
	 *
26
	 * @var  StatsJsonView
27
	 */
28
	private $view;
29
30
	/**
31
	 * Constructor.
32
	 *
33
	 * @param   StatsJsonView  $view  JSON view for displaying the statistics.
34
	 */
35
	public function __construct(StatsJsonView $view)
36
	{
37
		$this->view  = $view;
38
	}
39
40
	/**
41
	 * Execute the controller.
42
	 *
43
	 * @return  boolean
44
	 */
45
	public function execute()
46
	{
47
		$this->getApplication()->outputTitle('Creating Statistics Snapshot');
48
49
		// We want the full raw data set for our snapshot
50
		$this->view->isAuthorizedRaw(true);
51
52
		$file = APPROOT . '/snapshots/' . date('YmdHis');
53
54
		if (!file_put_contents($file, $this->view->render()))
55
		{
56
			throw new \RuntimeException('Failed writing snapshot to the filesystem at ' . $file);
57
		}
58
59
		$this->getApplication()->out('<info>Snapshot successfully recorded.</info>');
60
61
		return true;
62
	}
63
64
	/**
65
	 * Get the command's description
66
	 *
67
	 * @return  string
68
	 */
69
	public function getDescription() : string
70
	{
71
		return 'Takes a snapshot of the statistics data.';
72
	}
73
74
	/**
75
	 * Get the command's title
76
	 *
77
	 * @return  string
78
	 */
79
	public function getTitle() : string
80
	{
81
		return 'Stats Snapshot';
82
	}
83
}
84