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

HelpCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 8
dl 0
loc 70
ccs 0
cts 34
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 0 36 3
A getDescription() 0 4 1
A getTitle() 0 4 1
1
<?php
2
3
namespace Stats\Commands;
4
5
use Joomla\Application\Cli\ColorStyle;
6
use Joomla\Application\Cli\Output\Processor\ColorProcessor;
7
use Joomla\Controller\AbstractController;
8
use Stats\CommandInterface;
9
10
/**
11
 * Help command
12
 *
13
 * @method         \Stats\CliApplication  getApplication()  Get the application object.
14
 * @property-read  \Stats\CliApplication  $app              Application object
15
 *
16
 * @since          1.0
17
 */
18
class HelpCommand extends AbstractController implements CommandInterface
19
{
20
	/**
21
	 * Execute the controller.
22
	 *
23
	 * @return  boolean
24
	 *
25
	 * @since   1.0
26
	 */
27
	public function execute()
28
	{
29
		/** @var ColorProcessor $processor */
30
		$processor = $this->getApplication()->getOutput()->getProcessor();
31
		$processor->addStyle('cmd', new ColorStyle('magenta'));
32
33
		$executable = basename($this->getApplication()->input->executable);
34
35
		$commands = $this->getApplication()->getConsole()->getCommands();
0 ignored issues
show
Unused Code introduced by
$commands is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36
37
		$this->getApplication()->outputTitle($this->getTitle());
38
39
		$this->getApplication()->out(
40
			sprintf('Usage: <info>%s</info> <cmd><command></cmd>',
41
				$executable
42
			)
43
		);
44
45
		$this->getApplication()->out()
46
			->out('Available commands:')
47
			->out();
48
49
		foreach ($this->getApplication()->getConsole()->getCommands() as $cName => $command)
50
		{
51
			$this->getApplication()->out('<cmd>' . $cName . '</cmd>');
52
53
			if ($command->getDescription())
54
			{
55
				$this->getApplication()->out('    ' . $command->getDescription());
56
			}
57
58
			$this->getApplication()->out();
59
		}
60
61
		return true;
62
	}
63
64
	/**
65
	 * Get the command's description
66
	 *
67
	 * @return  string
68
	 *
69
	 * @since   1.0
70
	 */
71
	public function getDescription()
72
	{
73
		return 'Provides basic use information for the stats application.';
74
	}
75
76
	/**
77
	 * Get the command's title
78
	 *
79
	 * @return  string
80
	 *
81
	 * @since   1.0
82
	 */
83
	public function getTitle()
84
	{
85
		return 'Joomla Stats Application';
86
	}
87
}
88