Completed
Push — master ( d2a193...a63b69 )
by Michael
02:24
created

StatusCommand::getDescription()   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\Database;
4
5
use Joomla\Controller\AbstractController;
6
use Stats\CommandInterface;
7
use Stats\Database\Migrations;
8
9
/**
10
 * CLI command for checking the database migration status
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 StatusCommand extends AbstractController implements CommandInterface
18
{
19
	/**
20
	 * Database migrations helper
21
	 *
22
	 * @var    Migrations
23
	 * @since  1.0
24
	 */
25
	private $migrations;
26
27
	/**
28
	 * Constructor.
29
	 *
30
	 * @param   Migrations  $migrations  Database migrations helper
31
	 *
32
	 * @since   1.0
33
	 */
34
	public function __construct(Migrations $migrations)
35
	{
36
		$this->migrations = $migrations;
37
	}
38
39
	/**
40
	 * Execute the command.
41
	 *
42
	 * @return  void
43
	 *
44
	 * @since   1.0
45
	 */
46
	public function execute()
47
	{
48
		$this->getApplication()->outputTitle('Database Migrations: Check Status');
49
50
		$status = $this->migrations->checkStatus();
51
52
		if ($status['latest'])
53
		{
54
			$this->getApplication()->out('<fg=green;options=bold>Your database is up-to-date.</fg=green;options=bold>');
55
		}
56
		else
57
		{
58
			$this->getApplication()->out(
59
				'<comment>' . sprintf('Your database is not up-to-date. You are missing %d migrations.', $status['missingMigrations']) . '</comment>'
60
			)
61
				->out()
62
				->out('<comment>' . sprintf('Current Version: %1$s', $status['currentVersion']) . '</comment>')
63
				->out('<comment>' . sprintf('Latest Version: %1$s', $status['latestVersion']) . '</comment>')
64
				->out()
65
				->out(sprintf('To update, run the <fg=magenta>%1$s</fg=magenta> command.', 'database:migrate'));
66
		}
67
	}
68
69
	/**
70
	 * Get the command's description
71
	 *
72
	 * @return  string
73
	 *
74
	 * @since   1.0
75
	 */
76
	public function getDescription()
77
	{
78
		return 'Check the database migration status.';
79
	}
80
81
	/**
82
	 * Get the command's title
83
	 *
84
	 * @return  string
85
	 *
86
	 * @since   1.0
87
	 */
88
	public function getTitle()
89
	{
90
		return 'Database Migrations Status';
91
	}
92
}
93