This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace HM\BackUpWordPress; |
||
4 | |||
5 | /** |
||
6 | * The base Backup Engine |
||
7 | * |
||
8 | * Base Backup Engine types should extend this class and call parent::__construct in |
||
9 | * there constructor. |
||
10 | * |
||
11 | * Defines base functionality shared across all types of backups |
||
12 | */ |
||
13 | abstract class Backup_Engine { |
||
14 | |||
15 | /** |
||
16 | * An array of backup errors. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | private $errors = array(); |
||
21 | |||
22 | /** |
||
23 | * An array of backup warnings. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | private $warnings = array(); |
||
28 | |||
29 | public function __construct() { |
||
30 | |||
31 | /** |
||
32 | * Raise the `memory_limit` and `max_execution time` |
||
33 | * |
||
34 | * Respects the WP_MAX_MEMORY_LIMIT Constant and the `admin_memory_limit` |
||
35 | * filter. |
||
36 | */ |
||
37 | @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); |
||
0 ignored issues
–
show
|
|||
38 | @set_time_limit( 0 ); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
39 | |||
40 | // Set a custom error handler so we can track errors |
||
41 | set_error_handler( array( $this, 'error_handler' ) ); |
||
42 | |||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Backup Engine Types should always implement the `verify_backup` method. |
||
47 | * |
||
48 | * @return bool Whether the backup completed successfully or not. |
||
49 | */ |
||
50 | abstract public function verify_backup(); |
||
51 | |||
52 | /** |
||
53 | * Get the full filepath to the backup file. |
||
54 | * |
||
55 | * @return string The backup filepath. |
||
56 | */ |
||
57 | public function get_backup_filepath() { |
||
58 | return trailingslashit( Path::get_path() ) . $this->get_backup_filename(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Get the filename of the backup. |
||
63 | * |
||
64 | * @return string The backup filename. |
||
65 | */ |
||
66 | public function get_backup_filename() { |
||
67 | return $this->backup_filename; |
||
0 ignored issues
–
show
The property
backup_filename does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Set the filename of the backup. |
||
72 | * |
||
73 | * @param string $filename The backup filename. |
||
74 | */ |
||
75 | public function set_backup_filename( $filename ) { |
||
76 | $this->backup_filename = strtolower( sanitize_file_name( remove_accents( $filename ) ) ); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Get the array of errors encountered during the backup process. |
||
81 | * |
||
82 | * @param string $context The context for the error, usually the Backup |
||
0 ignored issues
–
show
Should the type for parameter
$context not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
83 | * Engine that encountered the error. |
||
84 | * |
||
85 | * @return array The array of errors. |
||
86 | */ |
||
87 | View Code Duplication | public function get_errors( $context = null ) { |
|
88 | |||
89 | // Only return a specific contexts errors. |
||
90 | if ( ! empty( $context ) ) { |
||
91 | return isset( $this->errors[ $context ] ) ? $this->errors[ $context ] : array(); |
||
92 | } |
||
93 | |||
94 | return $this->errors; |
||
95 | |||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Add an error to the errors array. |
||
100 | * |
||
101 | * An error is always treat as fatal and should only be used for unrecoverable |
||
102 | * issues with the backup process. |
||
103 | * |
||
104 | * @param string $context The context for the error. |
||
105 | * @param string $error The error that was encountered. |
||
106 | */ |
||
107 | View Code Duplication | public function error( $context, $error ) { |
|
108 | |||
109 | if ( empty( $context ) || empty( $error ) ) { |
||
110 | return; |
||
111 | } |
||
112 | |||
113 | // Ensure we don't store duplicate errors by md5'ing the error as the key |
||
114 | $this->errors[ $context ][ md5( implode( ':', (array) $error ) ) ] = $error; |
||
115 | |||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Get the array of warnings encountered during the backup process. |
||
120 | * |
||
121 | * @param string $context The context for the warning, usually the Backup |
||
0 ignored issues
–
show
Should the type for parameter
$context not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
122 | * Engine that encountered the warning. |
||
123 | * |
||
124 | * @return array The array of warnings. |
||
125 | */ |
||
126 | View Code Duplication | public function get_warnings( $context = null ) { |
|
127 | |||
128 | // Only return a specific contexts errors. |
||
129 | if ( ! empty( $context ) ) { |
||
130 | return isset( $this->warnings[ $context ] ) ? $this->warnings[ $context ] : array(); |
||
131 | } |
||
132 | |||
133 | return $this->warnings; |
||
134 | |||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Add an warning to the errors warnings. |
||
139 | * |
||
140 | * A warning is always treat as non-fatal and should only be used for recoverable |
||
141 | * issues with the backup process. |
||
142 | * |
||
143 | * @param string $context The context for the warning. |
||
144 | * @param string $error The warning that was encountered. |
||
0 ignored issues
–
show
There is no parameter named
$error . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
145 | */ |
||
146 | View Code Duplication | public function warning( $context, $warning ) { |
|
147 | |||
148 | if ( empty( $context ) || empty( $warning ) ) { |
||
149 | return; |
||
150 | } |
||
151 | |||
152 | // Ensure we don't store duplicate warnings by md5'ing the error as the key |
||
153 | $this->warnings[ $context ][ md5( implode( ':', (array) $warning ) ) ] = $warning; |
||
154 | |||
155 | } |
||
156 | |||
157 | /** |
||
158 | * Hooked into `set_error_handler` to catch any PHP errors that happen during |
||
159 | * the backup process. |
||
160 | * |
||
161 | * PHP errors are always treat as warnings rather than errors. |
||
162 | * |
||
163 | * @param int $type The level of error raised |
||
164 | * |
||
165 | * @return false Return false to pass the error back to PHP so it can |
||
0 ignored issues
–
show
|
|||
166 | * be handled natively. |
||
167 | */ |
||
168 | public function error_handler( $type ) { |
||
169 | |||
170 | // Skip strict & deprecated warnings |
||
171 | if ( ( defined( 'E_DEPRECATED' ) && E_DEPRECATED === $type ) || ( defined( 'E_STRICT' ) && E_STRICT === $type ) || 0 === error_reporting() ) { |
||
172 | return false; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Get the details of the error. |
||
177 | * |
||
178 | * These are: |
||
179 | * |
||
180 | * @param int $errorno The error level expressed as an integer/ |
||
181 | * @param string $errstr The error message. |
||
182 | * @param string $errfile The file that the error raised in. |
||
183 | * @param string $errorline The line number the error was raised on. |
||
184 | */ |
||
185 | $args = func_get_args(); |
||
186 | |||
187 | // Strip the error level |
||
188 | array_shift( $args ); |
||
189 | |||
190 | // Fire a warning for the PHP error passing the message, file and line number. |
||
191 | $this->warning( 'php', implode( ', ', array_splice( $args, 0, 3 ) ) ); |
||
192 | |||
193 | return false; |
||
194 | |||
195 | } |
||
196 | } |
||
197 |
If you suppress an error, we recommend checking for the error condition explicitly: