These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Console\Command; |
||
3 | |||
4 | use Redaxscript\Console\Parser; |
||
5 | use function array_key_exists; |
||
6 | use function array_keys; |
||
7 | use function end; |
||
8 | use function is_array; |
||
9 | use function is_string; |
||
10 | use function method_exists; |
||
11 | |||
12 | /** |
||
13 | * children class to execute the help command |
||
14 | * |
||
15 | * @since 3.0.0 |
||
16 | * |
||
17 | * @package Redaxscript |
||
18 | * @category Console |
||
19 | * @author Henry Ruhs |
||
20 | */ |
||
21 | |||
22 | class Help extends CommandAbstract |
||
23 | { |
||
24 | /** |
||
25 | * array of the command |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | |||
30 | protected $_commandArray = |
||
31 | [ |
||
32 | 'help' => |
||
33 | [ |
||
34 | 'description' => 'Help command', |
||
35 | 'argumentArray' => |
||
36 | [ |
||
37 | '<command>' => |
||
38 | [ |
||
39 | 'description' => 'Show help for the <command>' |
||
40 | ] |
||
41 | ] |
||
42 | ] |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * run the command |
||
47 | * |
||
48 | * @since 3.0.0 |
||
49 | * |
||
50 | * @param string $mode name of the mode |
||
51 | * |
||
52 | * @return string|null |
||
53 | */ |
||
54 | |||
55 | 2 | public function run(string $mode = null) : ?string |
|
56 | { |
||
57 | 2 | $parser = new Parser($this->_request); |
|
58 | 2 | $parser->init($mode); |
|
59 | |||
60 | /* run command */ |
||
61 | |||
62 | 2 | return $this->_list($parser->getArgument(1)); |
|
0 ignored issues
–
show
|
|||
63 | } |
||
64 | |||
65 | /** |
||
66 | * list the help |
||
67 | * |
||
68 | * @since 3.0.0 |
||
69 | * |
||
70 | * @param string $argumentKey |
||
71 | * |
||
72 | * @return string|null |
||
73 | */ |
||
74 | |||
75 | 2 | protected function _list(string $argumentKey = null) : ?string |
|
76 | { |
||
77 | 2 | $output = null; |
|
78 | |||
79 | /* collect each help */ |
||
80 | |||
81 | 2 | if (!is_string($argumentKey) || !is_array($this->_namespaceArray) || !array_key_exists($argumentKey, $this->_namespaceArray)) |
|
82 | { |
||
83 | 1 | $namespaceKeys = array_keys($this->_namespaceArray); |
|
84 | 1 | $lastKey = end($namespaceKeys); |
|
85 | 1 | foreach ($this->_namespaceArray as $commandKey => $commandClass) |
|
86 | { |
||
87 | 1 | if (method_exists($commandClass, 'getHelp')) |
|
88 | { |
||
89 | 1 | $command = new $commandClass($this->_registry, $this->_request, $this->_language, $this->_config); |
|
90 | 1 | $output .= $command->getHelp(); |
|
91 | 1 | if ($commandKey !== $lastKey) |
|
92 | { |
||
93 | 1 | $output .= PHP_EOL; |
|
94 | } |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | /* else single help */ |
||
100 | |||
101 | else |
||
102 | { |
||
103 | 1 | $commandClass = $this->_namespaceArray[$argumentKey]; |
|
104 | 1 | if (method_exists($commandClass, 'getHelp')) |
|
105 | { |
||
106 | 1 | $command = new $commandClass($this->_registry, $this->_request, $this->_language, $this->_config); |
|
107 | 1 | $output .= $command->getHelp(); |
|
108 | } |
||
109 | } |
||
110 | 2 | return $output; |
|
111 | } |
||
112 | } |
||
113 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.