Passed
Push — master ( d5adc1...45b033 )
by Fabio
06:12
created

TShellAppAction::renderHelp()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 15
c 1
b 0
f 0
nc 16
nop 0
dl 0
loc 19
rs 9.4555
1
<?php
2
/**
3
 * TShellAppAction 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
9
 */
10
11
namespace Prado\Shell;
12
13
/**
14
 * Base class for command line Application actions.
15
 *
16
 * @author Brad Anderson <belisoful[at]icloud[dot]com>
17
 * @package Prado\Shell
18
 * @since 4.2.0
19
 */
20
abstract class TShellAppAction extends TShellAction
21
{
22
	/**
23
	 * Checks if specified parameters are suitable for the specified action
24
	 * @param array $args parameters
25
	 * @return bool
26
	 */
27
	public function isValidAction($args)
28
	{
29
		return isset($args[2]) && 0 == strcasecmp($args[2], $this->action) &&
30
			count($args) - 1 >= count($this->parameters);
31
	}
32
33
	/**
34
	 * @return string
35
	 */
36
	public function renderHelp()
37
	{
38
		$params = [];
39
		foreach ($this->parameters as $v) {
40
			$params[] = '<' . $v . '>';
41
		}
42
		$parameters = implode(' ', $params);
43
		$options = [];
44
		foreach ($this->optional as $v) {
45
			$options[] = '[' . $v . ']';
46
		}
47
		$optional = (strlen($parameters) ? ' ' : '') . implode(' ', $options);
48
		$description = '';
49
		foreach (explode("\n", wordwrap($this->description, 65)) as $line) {
50
			$description .= '    ' . $line . "\n";
51
		}
52
		return <<<EOD
53
 app <directory> {$this->action} {$parameters}{$optional}
54
{$description}
55
56
EOD;
57
	}
58
}
59