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 Redaxscript\Db; |
||
6 | use Redaxscript\Installer; |
||
7 | use function method_exists; |
||
8 | |||
9 | /** |
||
10 | * children class to execute the uninstall command |
||
11 | * |
||
12 | * @since 3.0.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category Console |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Uninstall extends CommandAbstract |
||
20 | { |
||
21 | /** |
||
22 | * array of the command |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | |||
27 | protected $_commandArray = |
||
28 | [ |
||
29 | 'uninstall' => |
||
30 | [ |
||
31 | 'description' => 'Uninstall command', |
||
32 | 'argumentArray' => |
||
33 | [ |
||
34 | 'database' => |
||
35 | [ |
||
36 | 'description' => 'Uninstall the database' |
||
37 | ], |
||
38 | 'module' => |
||
39 | [ |
||
40 | 'description' => 'Uninstall the module', |
||
41 | 'optionArray' => |
||
42 | [ |
||
43 | 'alias' => |
||
44 | [ |
||
45 | 'description' => 'Required module alias' |
||
46 | ] |
||
47 | ] |
||
48 | ] |
||
49 | ] |
||
50 | ] |
||
51 | ]; |
||
52 | |||
53 | /** |
||
54 | * run the command |
||
55 | * |
||
56 | * @since 3.0.0 |
||
57 | * |
||
58 | * @param string $mode name of the mode |
||
59 | * |
||
60 | * @return string|null |
||
61 | */ |
||
62 | |||
63 | 4 | public function run(string $mode = null) : ?string |
|
64 | { |
||
65 | 4 | $parser = new Parser($this->_request); |
|
66 | 4 | $parser->init($mode); |
|
67 | |||
68 | /* run command */ |
||
69 | |||
70 | 4 | $argumentKey = $parser->getArgument(1); |
|
71 | 4 | $haltOnError = (bool)$parser->getOption('halt-on-error'); |
|
72 | 4 | if ($argumentKey === 'database') |
|
73 | { |
||
74 | 1 | return $this->_database() ? $this->success() : $this->error($haltOnError); |
|
75 | } |
||
76 | 3 | if ($argumentKey === 'module') |
|
77 | { |
||
78 | 2 | return $this->_module($parser->getOption()) ? $this->success() : $this->error($haltOnError); |
|
0 ignored issues
–
show
|
|||
79 | } |
||
80 | 1 | return $this->getHelp(); |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * uninstall the database |
||
85 | * |
||
86 | * @since 3.0.0 |
||
87 | * |
||
88 | * @return bool |
||
89 | */ |
||
90 | |||
91 | 1 | protected function _database() : bool |
|
92 | { |
||
93 | 1 | $installer = new Installer($this->_registry, $this->_request, $this->_language, $this->_config); |
|
94 | 1 | $installer->init(); |
|
95 | 1 | $installer->rawDrop(); |
|
96 | 1 | Db::clearCache(); |
|
97 | 1 | return Db::getStatus() === 1; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * uninstall the module |
||
102 | * |
||
103 | * @since 3.0.0 |
||
104 | * |
||
105 | * @param array $optionArray |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | |||
110 | 2 | protected function _module(array $optionArray = []) : bool |
|
111 | { |
||
112 | 2 | $alias = $this->prompt('alias', $optionArray); |
|
113 | 2 | $moduleClass = 'Redaxscript\Modules\\' . $alias . '\\' . $alias; |
|
114 | |||
115 | /* uninstall */ |
||
116 | |||
117 | 2 | if (method_exists($moduleClass, 'install')) |
|
118 | { |
||
119 | 1 | $module = new $moduleClass($this->_registry, $this->_request, $this->_language, $this->_config); |
|
120 | 1 | return $module->uninstall(); |
|
121 | } |
||
122 | 1 | return false; |
|
123 | } |
||
124 | } |
||
125 |
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.