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\Installer; |
||
6 | use function exec; |
||
7 | use function is_file; |
||
8 | |||
9 | /** |
||
10 | * children class to execute the restore command |
||
11 | * |
||
12 | * @since 3.0.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category Console |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Restore extends CommandAbstract |
||
20 | { |
||
21 | /** |
||
22 | * array of the command |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | |||
27 | protected $_commandArray = |
||
28 | [ |
||
29 | 'restore' => |
||
30 | [ |
||
31 | 'description' => 'Restore command', |
||
32 | 'argumentArray' => |
||
33 | [ |
||
34 | 'database' => |
||
35 | [ |
||
36 | 'description' => 'Restore the database', |
||
37 | 'optionArray' => |
||
38 | [ |
||
39 | 'directory' => |
||
40 | [ |
||
41 | 'description' => 'Required directory' |
||
42 | ], |
||
43 | 'file' => |
||
44 | [ |
||
45 | 'description' => 'Required file' |
||
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 | 3 | public function run(string $mode = null) : ?string |
|
64 | { |
||
65 | 3 | $parser = new Parser($this->_request); |
|
66 | 3 | $parser->init($mode); |
|
67 | |||
68 | /* run command */ |
||
69 | |||
70 | 3 | $argumentKey = $parser->getArgument(1); |
|
71 | 3 | $haltOnError = (bool)$parser->getOption('halt-on-error'); |
|
72 | 3 | if ($argumentKey === 'database') |
|
73 | { |
||
74 | 2 | return $this->_database($parser->getOptionArray()) ? $this->success() : $this->error($haltOnError); |
|
75 | } |
||
76 | 1 | return $this->getHelp(); |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * restore the database |
||
81 | * |
||
82 | * @since 3.0.0 |
||
83 | * |
||
84 | * @param array $optionArray |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | |||
89 | 2 | protected function _database(array $optionArray = []) : bool |
|
90 | { |
||
91 | 2 | $installer = new Installer($this->_registry, $this->_request, $this->_language, $this->_config); |
|
92 | 2 | $installer->init(); |
|
93 | 2 | $dbType = $this->_config->get('dbType'); |
|
94 | 2 | $dbHost = $this->_config->get('dbHost'); |
|
95 | 2 | $dbName = $this->_config->get('dbName'); |
|
96 | 2 | $dbUser = $this->_config->get('dbUser'); |
|
97 | 2 | $dbPassword = $this->_config->get('dbPassword'); |
|
98 | 2 | $directory = $this->prompt('directory', $optionArray); |
|
99 | 2 | $file = $this->prompt('file', $optionArray); |
|
100 | 2 | $path = $directory . DIRECTORY_SEPARATOR . $file; |
|
101 | |||
102 | /* restore */ |
||
103 | |||
104 | 2 | if (is_file($path)) |
|
105 | { |
||
106 | 1 | if ($dbType === 'mysql' && $dbHost && $dbName && $dbUser && $dbPassword) |
|
0 ignored issues
–
show
The expression
$dbName of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
The expression
$dbUser of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
The expression
$dbPassword of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
|
|||
107 | { |
||
108 | $command = 'mysql --host=' . $dbHost . ' --user=' . $dbUser . ' --password=' . $dbPassword . ' ' . $dbName . ' < ' . $path; |
||
109 | } |
||
110 | 1 | if ($dbType === 'pgsql' && $dbHost && $dbName && $dbUser && $dbPassword) |
|
0 ignored issues
–
show
The expression
$dbHost of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
The expression
$dbName of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
The expression
$dbUser of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
The expression
$dbPassword of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
|
|||
111 | { |
||
112 | $command = 'psql postgres://' . $dbUser . ':' . $dbPassword . '@' . $dbHost . '/' . $dbName . ' < ' . $path; |
||
113 | } |
||
114 | 1 | if ($dbType === 'sqlite' && $dbHost) |
|
0 ignored issues
–
show
The expression
$dbHost of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
|
|||
115 | { |
||
116 | 1 | $command = 'sqlite3 ' . $dbHost . ' .dump < ' . $path; |
|
117 | } |
||
118 | 1 | if ($command) |
|
119 | { |
||
120 | 1 | $installer->rawDrop(); |
|
121 | 1 | exec($command, $outputArray, $status); |
|
0 ignored issues
–
show
The variable
$command does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
122 | } |
||
123 | 1 | return $status === 0; |
|
0 ignored issues
–
show
The variable
$status does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
124 | } |
||
125 | 1 | return false; |
|
126 | } |
||
127 | } |
||
128 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: