Passed
Push — master ( 5fd064...896ccb )
by Fabio
04:59
created

THelpAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 17 4
1
<?php
2
/**
3
 * THelpAction class file
4
 *
5
 * @author Brad Anderson <[email protected]>
6
 * @link https://github.com/pradosoft/prado
7
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
8
 * @package Prado\Shell\Actions
9
 */
10
11
namespace Prado\Shell\Actions;
12
13
use Prado\Prado;
14
use Prado\Shell\TShellAction;
15
16
/**
17
 * THelpAction class.
18
 *
19
 * The help for a specific command.
20
 *
21
 * @author Brad Anderson <belisoful[at]icloud[dot]com>
22
 * @package Prado\Shell\Actions
23
 * @since 4.2.0
24
 */
25
class THelpAction extends TShellAction
26
{
27
	protected $action = 'help';
28
	protected $methods = ['index'];
29
	protected $parameters = [null];
30
	protected $optional = ['command'];
31
	protected $description = [
32
		'Provides help information about shell commands.',
33
		'Displays available commands or detailed command information.'];
34
	
35
	/**
36
	 * displays help for a specific command or the general help
37
	 * @param array $args parameters
38
	 * @return bool is the action handled
39
	 */
40
	public function actionIndex($args)
41
	{
42
		if (isset($args[1])) {
43
			foreach (Prado::getApplication()->getShellActions() as $action) {
0 ignored issues
show
Bug introduced by
The method getShellActions() does not exist on Prado\TApplication. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
			foreach (Prado::getApplication()->/** @scrutinizer ignore-call */ getShellActions() as $action) {
Loading history...
44
				$cmdname = $action->getAction();
45
				if (0 === strncasecmp($cmdname, $args[1], strlen($cmdname))) {
46
					$action->setWriter($this->getWriter());
47
					$action->renderHelpCommand($args[1]);
48
					return true;
49
				}
50
			}
51
		} else {
52
			$app = Prado::getApplication();
53
			$app->printHelp($this->getWriter());
0 ignored issues
show
Bug introduced by
The method printHelp() does not exist on Prado\TApplication. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
			$app->/** @scrutinizer ignore-call */ 
54
         printHelp($this->getWriter());
Loading history...
54
			return true;
55
		}
56
		return false;
57
	}
58
}
59