Completed
Push — mysql_improvements ( 2e95ce...dedbef )
by Michael
03:52
created

CliApplication::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 5
crap 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
class CliApplication extends AbstractCliApplication
22
{
23
	/**
24
	 * The application's console object
25
	 *
26
	 * @var  Console
27
	 */
28
	private $console;
29
30
	/**
31
	 * CliApplication constructor.
32
	 *
33
	 * @param   Input\Cli  $input     The application's input object.
34
	 * @param   Registry   $config    The application's configuration.
35
	 * @param   CliOutput  $output    The application's output object.
36
	 * @param   CliInput   $cliInput  The application's CLI input handler.
37
	 * @param   Console    $console   The application's console object.
38
	 */
39
	public function __construct(Cli $input, Registry $config, CliOutput $output, CliInput $cliInput, Console $console)
40
	{
41
		parent::__construct($input, $config, $output, $cliInput);
42
43
		$this->console = $console;
44
	}
45
46
	/**
47
	 * Method to run the application routines.
48
	 *
49
	 * @return  void
50
	 *
51
	 * @throws  \InvalidArgumentException
52
	 */
53
	protected function doExecute()
54
	{
55
		$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...
56
57
		$command  = !empty($args[0]) ? $args[0] : 'help';
58
		$commands = $this->getConsole()->getCommands();
59
60
		if (!array_key_exists($command, $commands))
61
		{
62
			throw new \InvalidArgumentException(sprintf('The "%s" command is not valid.', $command));
63
		}
64
65
		// Execute the command
66
		$commands[$command]->execute();
67
	}
68
69
	/**
70
	 * Get the application's console object
71
	 *
72
	 * @return  Console
73
	 */
74
	public function getConsole() : Console
75
	{
76
		return $this->console;
77
	}
78
79
	/**
80
	 * Output a nicely formatted title for the application.
81
	 *
82
	 * @param   string  $title     The title to display.
83
	 * @param   string  $subTitle  A subtitle.
84
	 * @param   int     $width     Total width in chars.
85
	 *
86
	 * @return  $this
87
	 */
88
	public function outputTitle(string $title, string $subTitle = '', int $width = 60) : CliApplication
89
	{
90
		$this->out(str_repeat('-', $width));
91
		$this->out(str_repeat(' ', $width / 2 - (strlen($title) / 2)) . '<title>' . $title . '</title>');
92
93
		if ($subTitle)
94
		{
95
			$this->out(str_repeat(' ', $width / 2 - (strlen($subTitle) / 2)) . '<b>' . $subTitle . '</b>');
96
		}
97
98
		$this->out(str_repeat('-', $width));
99
100
		return $this;
101
	}
102
}
103