| Conditions | 13 |
| Paths | 482 |
| Total Lines | 99 |
| Code Lines | 54 |
| Lines | 2 |
| Ratio | 2.02 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 210 | private function __xcloner_scheduler_callback($id, $schedule) |
||
| 211 | { |
||
| 212 | set_time_limit(0); |
||
| 213 | |||
| 214 | $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
||
| 215 | $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
||
| 216 | $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
||
| 217 | $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
||
| 218 | $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
||
| 219 | |||
| 220 | if($schedule['recurrence'] == "single") |
||
| 221 | { |
||
| 222 | $this->disable_single_cron($schedule['id']); |
||
| 223 | } |
||
| 224 | |||
| 225 | if(!$schedule) |
||
| 226 | { |
||
| 227 | $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
||
| 228 | return; |
||
| 229 | } |
||
| 230 | |||
| 231 | $this->update_hash($schedule['id'], $this->xcloner_settings->get_hash()); |
||
| 232 | |||
| 233 | $this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON")); |
||
| 234 | |||
| 235 | $this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files'])); |
||
| 236 | |||
| 237 | $init = 1; |
||
| 238 | $continue = 1; |
||
| 239 | |||
| 240 | while($continue) |
||
| 241 | { |
||
| 242 | $continue = $this->xcloner_file_system->start_file_recursion($init); |
||
| 243 | |||
| 244 | $init = 0; |
||
| 245 | } |
||
| 246 | |||
| 247 | $this->logger->info(sprintf("File scan finished"), array("CRON")); |
||
| 248 | |||
| 249 | $this->logger->info(sprintf("Starting the database backup"), array("CRON")); |
||
| 250 | |||
| 251 | $init = 1; |
||
| 252 | $return['finished'] = 0; |
||
| 253 | |||
| 254 | while(!$return['finished']) |
||
| 255 | { |
||
| 256 | $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
||
| 257 | $init = 0; |
||
| 258 | } |
||
| 259 | |||
| 260 | $this->logger->info(sprintf("Database backup done"), array("CRON")); |
||
| 261 | |||
| 262 | $this->logger->info(sprintf("Starting file archive process"), array("CRON")); |
||
| 263 | |||
| 264 | $init = 0; |
||
| 265 | $return['finished'] = 0; |
||
| 266 | $return['extra'] = array(); |
||
| 267 | |||
| 268 | while(!$return['finished']) |
||
| 269 | { |
||
| 270 | $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
||
| 271 | $init = 0; |
||
| 272 | } |
||
| 273 | $this->logger->info(sprintf("File archive process FINISHED."), array("CRON")); |
||
| 274 | |||
| 275 | //getting the last backup archive file |
||
| 276 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
||
| 277 | View Code Duplication | if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
| 278 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
||
| 279 | |||
| 280 | $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); |
||
| 281 | |||
| 282 | if($schedule['remote_storage'] and array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) |
||
| 283 | { |
||
| 284 | $backup_file = $return['extra']['backup_parent']; |
||
| 285 | |||
| 286 | $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
||
| 287 | |||
| 288 | if(method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) |
||
| 289 | call_user_func_array(array($this->xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $schedule['remote_storage'])); |
||
| 290 | } |
||
| 291 | |||
| 292 | |||
| 293 | if(isset($schedule['backup_params']->email_notification) and $to=$schedule['backup_params']->email_notification) |
||
| 294 | { |
||
| 295 | try{ |
||
| 296 | $from = "XCloner Schedule - ".$schedule['name']; |
||
| 297 | $additional['lines_total'] = $return['extra']['lines_total']; |
||
| 298 | $this->archive_system->send_notification($to, $from, "", $return['extra']['backup_parent'], $schedule, "", $additional); |
||
| 299 | }catch(Exception $e) |
||
| 300 | { |
||
| 301 | $this->logger->error($e->getMessage()); |
||
| 302 | } |
||
| 303 | } |
||
| 304 | |||
| 305 | $this->xcloner_file_system->remove_tmp_filesystem(); |
||
| 306 | |||
| 307 | $this->xcloner_file_system->backup_storage_cleanup(); |
||
| 308 | } |
||
| 309 | |||
| 336 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.