Completed
Push — master ( cd1493...0fdab2 )
by Michael
02:22
created

SnapshotCommand::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Stats\Commands;
4
5
use Joomla\Controller\AbstractController;
6
use Stats\CommandInterface;
7
use Stats\Views\Stats\StatsJsonView;
8
9
/**
10
 * Help command
11
 *
12
 * @method         \Stats\CliApplication  getApplication()  Get the application object.
13
 * @property-read  \Stats\CliApplication  $app              Application object
14
 *
15
 * @since          1.0
16
 */
17
class SnapshotCommand extends AbstractController implements CommandInterface
18
{
19
	/**
20
	 * JSON view for displaying the statistics.
21
	 *
22
	 * @var    StatsJsonView
23
	 * @since  1.0
24
	 */
25
	private $view;
26
27
	/**
28
	 * Constructor.
29
	 *
30
	 * @param   StatsJsonView  $view  JSON view for displaying the statistics.
31
	 *
32
	 * @since   1.0
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
	 * @since   1.0
45
	 */
46
	public function execute()
47
	{
48
		$this->getApplication()->outputTitle('Creating Statistics Snapshot');
49
50
		// We want the full raw data set for our snapshot
51
		$this->view->isAuthorizedRaw(true);
52
53
		$file = APPROOT . '/snapshots/' . date('YmdHis');
54
55
		if (!file_put_contents($file, $this->view->render()))
56
		{
57
			throw new \RuntimeException('Failed writing snapshot to the filesystem at ' . $file);
58
		}
59
60
		$this->getApplication()->out('<info>Snapshot successfully recorded.</info>');
61
62
		return true;
63
	}
64
65
	/**
66
	 * Get the command's description
67
	 *
68
	 * @return  string
69
	 *
70
	 * @since   1.0
71
	 */
72
	public function getDescription()
73
	{
74
		return 'Takes a snapshot of the statistics data.';
75
	}
76
77
	/**
78
	 * Get the command's title
79
	 *
80
	 * @return  string
81
	 *
82
	 * @since   1.0
83
	 */
84
	public function getTitle()
85
	{
86
		return 'Stats Snapshot';
87
	}
88
}
89