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

CliApplication   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 88
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A doExecute() 0 15 3
A getConsole() 0 4 1
A outputTitle() 0 14 2
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;
10
11
use Joomla\Application\AbstractCliApplication;
12
use Joomla\Application\Cli\{
13
	CliInput, CliOutput
14
};
15
use Joomla\Input\Cli;
16
use Joomla\Registry\Registry;
17
18
/**
19
 * CLI application for the stats server
20
 *
21
 * @since  1.0
22
 */
23
class CliApplication extends AbstractCliApplication
24
{
25
	/**
26
	 * The application's console object
27
	 *
28
	 * @var    Console
29
	 * @since  1.0
30
	 */
31
	private $console;
32
33
	/**
34
	 * CliApplication constructor.
35
	 *
36
	 * @param   Input\Cli  $input     The application's input object.
37
	 * @param   Registry   $config    The application's configuration.
38
	 * @param   CliOutput  $output    The application's output object.
39
	 * @param   CliInput   $cliInput  The application's CLI input handler.
40
	 * @param   Console    $console   The application's console object.
41
	 */
42
	public function __construct(Cli $input, Registry $config, CliOutput $output, CliInput $cliInput, Console $console)
43
	{
44
		parent::__construct($input, $config, $output, $cliInput);
45
46
		$this->console = $console;
47
	}
48
49
	/**
50
	 * Method to run the application routines.
51
	 *
52
	 * @return  void
53
	 *
54
	 * @since   1.0
55
	 * @throws  \InvalidArgumentException
56
	 */
57
	protected function doExecute()
58
	{
59
		$args = $this->input->args;
0 ignored issues
show
Bug introduced by
The property args does not seem to exist in Joomla\Input\Input.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
60
61
		$command  = !empty($args[0]) ? $args[0] : 'help';
62
		$commands = $this->getConsole()->getCommands();
63
64
		if (!array_key_exists($command, $commands))
65
		{
66
			throw new \InvalidArgumentException(sprintf('The "%s" command is not valid.', $command));
67
		}
68
69
		// Execute the command
70
		$commands[$command]->execute();
71
	}
72
73
	/**
74
	 * Get the application's console object
75
	 *
76
	 * @return  Console
77
	 *
78
	 * @since   1.0
79
	 */
80
	public function getConsole() : Console
81
	{
82
		return $this->console;
83
	}
84
85
	/**
86
	 * Output a nicely formatted title for the application.
87
	 *
88
	 * @param   string  $title     The title to display.
89
	 * @param   string  $subTitle  A subtitle.
90
	 * @param   int     $width     Total width in chars.
91
	 *
92
	 * @return  $this
93
	 *
94
	 * @since   1.0
95
	 */
96
	public function outputTitle(string $title, string $subTitle = '', int $width = 60) : CliApplication
97
	{
98
		$this->out(str_repeat('-', $width));
99
		$this->out(str_repeat(' ', $width / 2 - (strlen($title) / 2)) . '<title>' . $title . '</title>');
100
101
		if ($subTitle)
102
		{
103
			$this->out(str_repeat(' ', $width / 2 - (strlen($subTitle) / 2)) . '<b>' . $subTitle . '</b>');
104
		}
105
106
		$this->out(str_repeat('-', $width));
107
108
		return $this;
109
	}
110
}
111