Completed
Push — master ( 10f95b...bf15d4 )
by Michael
09:02
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 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 72
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

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
 * @since          1.0
22
 */
23
class SnapshotCommand extends AbstractController implements CommandInterface
24
{
25
	/**
26
	 * JSON view for displaying the statistics.
27
	 *
28
	 * @var    StatsJsonView
29
	 * @since  1.0
30
	 */
31
	private $view;
32
33
	/**
34
	 * Constructor.
35
	 *
36
	 * @param   StatsJsonView  $view  JSON view for displaying the statistics.
37
	 *
38
	 * @since   1.0
39
	 */
40
	public function __construct(StatsJsonView $view)
41
	{
42
		$this->view  = $view;
43
	}
44
45
	/**
46
	 * Execute the controller.
47
	 *
48
	 * @return  boolean
49
	 *
50
	 * @since   1.0
51
	 */
52
	public function execute()
53
	{
54
		$this->getApplication()->outputTitle('Creating Statistics Snapshot');
55
56
		// We want the full raw data set for our snapshot
57
		$this->view->isAuthorizedRaw(true);
58
59
		$file = APPROOT . '/snapshots/' . date('YmdHis');
60
61
		if (!file_put_contents($file, $this->view->render()))
62
		{
63
			throw new \RuntimeException('Failed writing snapshot to the filesystem at ' . $file);
64
		}
65
66
		$this->getApplication()->out('<info>Snapshot successfully recorded.</info>');
67
68
		return true;
69
	}
70
71
	/**
72
	 * Get the command's description
73
	 *
74
	 * @return  string
75
	 *
76
	 * @since   1.0
77
	 */
78
	public function getDescription() : string
79
	{
80
		return 'Takes a snapshot of the statistics data.';
81
	}
82
83
	/**
84
	 * Get the command's title
85
	 *
86
	 * @return  string
87
	 *
88
	 * @since   1.0
89
	 */
90
	public function getTitle() : string
91
	{
92
		return 'Stats Snapshot';
93
	}
94
}
95