Completed
Push — master ( 10f95b...bf15d4 )
by Michael
09:02
created

StatusCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 78
ccs 0
cts 20
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B execute() 0 24 2
A getDescription() 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\Database;
10
11
use Joomla\Controller\AbstractController;
12
use Joomla\StatsServer\CommandInterface;
13
use Joomla\StatsServer\Database\Migrations;
14
15
/**
16
 * CLI command for checking the database migration status
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 StatusCommand extends AbstractController implements CommandInterface
24
{
25
	/**
26
	 * Database migrations helper
27
	 *
28
	 * @var    Migrations
29
	 * @since  1.0
30
	 */
31
	private $migrations;
32
33
	/**
34
	 * Constructor.
35
	 *
36
	 * @param   Migrations  $migrations  Database migrations helper
37
	 *
38
	 * @since   1.0
39
	 */
40
	public function __construct(Migrations $migrations)
41
	{
42
		$this->migrations = $migrations;
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('Database Migrations: Check Status');
55
56
		$status = $this->migrations->checkStatus();
57
58
		if ($status['latest'])
59
		{
60
			$this->getApplication()->out('<fg=green;options=bold>Your database is up-to-date.</fg=green;options=bold>');
61
		}
62
		else
63
		{
64
			$this->getApplication()->out(
65
				'<comment>' . sprintf('Your database is not up-to-date. You are missing %d migrations.', $status['missingMigrations']) . '</comment>'
66
			)
67
				->out()
68
				->out('<comment>' . sprintf('Current Version: %1$s', $status['currentVersion']) . '</comment>')
69
				->out('<comment>' . sprintf('Latest Version: %1$s', $status['latestVersion']) . '</comment>')
70
				->out()
71
				->out(sprintf('To update, run the <fg=magenta>%1$s</fg=magenta> command.', 'database:migrate'));
72
		}
73
74
		return true;
75
	}
76
77
	/**
78
	 * Get the command's description
79
	 *
80
	 * @return  string
81
	 *
82
	 * @since   1.0
83
	 */
84
	public function getDescription() : string
85
	{
86
		return 'Check the database migration status.';
87
	}
88
89
	/**
90
	 * Get the command's title
91
	 *
92
	 * @return  string
93
	 *
94
	 * @since   1.0
95
	 */
96
	public function getTitle() : string
97
	{
98
		return 'Database Migrations Status';
99
	}
100
}
101