Fixed: CodeFactor issues

This commit is contained in:
Bogdan Rapaić 2020-04-17 19:30:50 +02:00 committed by GitHub
parent b0aea12aab
commit 15c17d71c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,5 @@
<?php <?php
/**
/*
*
* Credits * Credits
* *
* Plugin-Name: WP Staging * Plugin-Name: WP Staging
@ -12,16 +10,14 @@
* *
* The code is used for the MainWP Staging Extension * The code is used for the MainWP Staging Extension
* Extension URL: https://mainwp.com/extension/staging/ * Extension URL: https://mainwp.com/extension/staging/
*
*/ */
class MainWP_Child_Staging { class MainWP_Child_Staging {
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
static function Instance() { public static function Instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Staging(); self::$instance = new MainWP_Child_Staging();
} }
@ -45,7 +41,7 @@ class MainWP_Child_Staging {
public function init() { public function init() {
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) { if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
return; return;
} }
@ -53,7 +49,7 @@ class MainWP_Child_Staging {
return; return;
} }
if ( get_option( 'mainwp_wp_staging_hide_plugin' ) === 'hide' ) { if ( 'hide' === get_option( 'mainwp_wp_staging_hide_plugin' ) ) {
add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) );
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
@ -66,28 +62,29 @@ class MainWP_Child_Staging {
try { try {
$information['syncWPStaging'] = $this->get_sync_data(); $information['syncWPStaging'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch ( Exception $e ) {
// do not exit // ok!
} }
} }
return $information; return $information;
} }
// ok
public function get_sync_data() { public function get_sync_data() {
return $this->get_overview(); return $this->get_overview();
} }
public function action() { public function action() {
if ( ! $this->is_plugin_installed ) { if ( ! $this->is_plugin_installed ) {
MainWP_Helper::write( array( 'error' => 'Please install WP Staging plugin on child website' ) ); MainWP_Helper::write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) );
} }
if ( ! class_exists( 'WPStaging\WPStaging' ) ) { if ( ! class_exists( 'WPStaging\WPStaging' ) ) {
require_once WPSTG_PLUGIN_DIR . 'apps/Core/WPStaging.php'; require_once WPSTG_PLUGIN_DIR . 'apps/Core/WPStaging.php';
} }
\WPStaging\WPStaging::getInstance();
\WPStaging\WPStaging::getInstance();
$information = array(); $information = array();
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) {
if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' ); MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' );
} }
@ -149,14 +146,14 @@ class MainWP_Child_Staging {
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
function set_showhide() { public function set_showhide() {
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
MainWP_Helper::update_option( 'mainwp_wp_staging_hide_plugin', $hide, 'yes' ); MainWP_Helper::update_option( 'mainwp_wp_staging_hide_plugin', $hide, 'yes' );
$information['result'] = 'SUCCESS'; $information['result'] = 'SUCCESS';
return $information; return $information;
} }
function save_settings() { public function save_settings() {
$settings = $_POST['settings']; $settings = $_POST['settings'];
$filters = array( $filters = array(
'queryLimit', 'queryLimit',
@ -167,12 +164,10 @@ class MainWP_Child_Staging {
'disableAdminLogin', 'disableAdminLogin',
'querySRLimit', 'querySRLimit',
'maxFileSize', 'maxFileSize',
// 'wpSubDirectory', // removed
'debugMode', 'debugMode',
'unInstallOnDelete', 'unInstallOnDelete',
'checkDirectorySize', 'checkDirectorySize',
'optimizer', 'optimizer',
// 'loginSlug' // removed
); );
$save_fields = array(); $save_fields = array();
@ -193,11 +188,9 @@ class MainWP_Child_Staging {
} }
public function get_scan() { public function get_scan() {
// Scan
$scan = new WPStaging\Backend\Modules\Jobs\Scan(); $scan = new WPStaging\Backend\Modules\Jobs\Scan();
$scan->start(); $scan->start();
// Get Options
$options = $scan->getOptions(); $options = $scan->getOptions();
$return = array( $return = array(
@ -214,7 +207,6 @@ class MainWP_Child_Staging {
$cloneNameLength = strlen( $cloneName ); $cloneNameLength = strlen( $cloneName );
$clones = get_option( 'wpstg_existing_clones_beta', array() ); $clones = get_option( 'wpstg_existing_clones_beta', array() );
// Check clone name length
if ( $cloneNameLength < 1 || $cloneNameLength > 16 ) { if ( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
echo array( echo array(
'status' => 'failed', 'status' => 'failed',
@ -232,7 +224,7 @@ class MainWP_Child_Staging {
public function ajaxStartClone() { public function ajaxStartClone() {
$this->url = ''; // to fix warning $this->url = '';
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
if ( ! $cloning->save() ) { if ( ! $cloning->save() ) {
@ -246,7 +238,6 @@ class MainWP_Child_Staging {
} }
public function ajaxCloneDatabase() { public function ajaxCloneDatabase() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start(); return $cloning->start();
@ -256,7 +247,6 @@ class MainWP_Child_Staging {
* Ajax Prepare Directories (get listing of files) * Ajax Prepare Directories (get listing of files)
*/ */
public function ajaxPrepareDirectories() { public function ajaxPrepareDirectories() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start(); return $cloning->start();
@ -266,7 +256,6 @@ class MainWP_Child_Staging {
* Ajax Clone Files * Ajax Clone Files
*/ */
public function ajaxCopyFiles() { public function ajaxCopyFiles() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start(); return $cloning->start();
@ -284,9 +273,8 @@ class MainWP_Child_Staging {
* Ajax Finish * Ajax Finish
*/ */
public function ajaxFinish() { public function ajaxFinish() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
$this->url = ''; // to fix warning $this->url = '';
$return = $cloning->start(); $return = $cloning->start();
$return->blogInfoName = get_bloginfo( 'name' ); $return->blogInfoName = get_bloginfo( 'name' );
@ -297,7 +285,6 @@ class MainWP_Child_Staging {
* Ajax Delete Confirmation * Ajax Delete Confirmation
*/ */
public function ajaxDeleteConfirmation() { public function ajaxDeleteConfirmation() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete(); $delete = new WPStaging\Backend\Modules\Jobs\Delete();
$delete->setData(); $delete->setData();
$clone = $delete->getClone(); $clone = $delete->getClone();
@ -305,6 +292,7 @@ class MainWP_Child_Staging {
'clone' => $clone, 'clone' => $clone,
'deleteTables' => $delete->getTables(), 'deleteTables' => $delete->getTables(),
); );
return $result; return $result;
} }
@ -312,8 +300,8 @@ class MainWP_Child_Staging {
* Delete clone * Delete clone
*/ */
public function ajaxDeleteClone() { public function ajaxDeleteClone() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete(); $delete = new WPStaging\Backend\Modules\Jobs\Delete();
return $delete->start(); return $delete->start();
} }
@ -322,16 +310,17 @@ class MainWP_Child_Staging {
*/ */
public function ajaxCancelClone() { public function ajaxCancelClone() {
$cancel = new WPStaging\Backend\Modules\Jobs\Cancel(); $cancel = new WPStaging\Backend\Modules\Jobs\Cancel();
return $cancel->start(); return $cancel->start();
} }
public function ajaxCancelUpdate() { public function ajaxCancelUpdate() {
$cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate(); $cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate();
return $cancel->start(); return $cancel->start();
} }
public function ajaxUpdateProcess() { public function ajaxUpdateProcess() {
$cloning = new WPStaging\Backend\Modules\Jobs\Updating(); $cloning = new WPStaging\Backend\Modules\Jobs\Updating();
if ( ! $cloning->save() ) { if ( ! $cloning->save() ) {
@ -348,7 +337,6 @@ class MainWP_Child_Staging {
return $this->hasFreeDiskSpace(); return $this->hasFreeDiskSpace();
} }
// from wp-staging plugin
public function hasFreeDiskSpace() { public function hasFreeDiskSpace() {
if ( ! function_exists( 'disk_free_space' ) ) { if ( ! function_exists( 'disk_free_space' ) ) {
return null; return null;
@ -368,8 +356,7 @@ class MainWP_Child_Staging {
return $data; return $data;
} }
// from wp-staging plugin public function getDirectorySizeInclSubdirs( $dir ) {
function getDirectorySizeInclSubdirs( $dir ) {
$size = 0; $size = 0;
foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) { foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) {
$size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each ); $size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each );
@ -377,7 +364,6 @@ class MainWP_Child_Staging {
return $size; return $size;
} }
// from wp-staging plugin
public function formatSize( $bytes, $precision = 2 ) { public function formatSize( $bytes, $precision = 2 ) {
if ( (float) $bytes < 1 ) { if ( (float) $bytes < 1 ) {
return ''; return '';
@ -386,8 +372,8 @@ class MainWP_Child_Staging {
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' ); $units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
$bytes = (float) $bytes; $bytes = (float) $bytes;
$base = log($bytes) / log(1000); // 1024 would be for MiB KiB etc $base = log( $bytes ) / log( 1000 );
$pow = pow(1000, $base - floor($base)); // Same rule for 1000 $pow = pow( 1000, $base - floor( $base ) );
return round( $pow, $precision ) . ' ' . $units[ (int) floor( $base ) ]; return round( $pow, $precision ) . ' ' . $units[ (int) floor( $base ) ];
} }
@ -413,12 +399,13 @@ class MainWP_Child_Staging {
} }
} }
function hide_update_notice( $slugs ) { public function hide_update_notice( $slugs ) {
$slugs[] = 'wp-staging/wp-staging.php'; $slugs[] = 'wp-staging/wp-staging.php';
return $slugs; return $slugs;
} }
function remove_update_nag( $value ) { public function remove_update_nag( $value ) {
if ( isset( $_POST['mainwpsignature'] ) ) { if ( isset( $_POST['mainwpsignature'] ) ) {
return $value; return $value;
} }
@ -438,4 +425,3 @@ class MainWP_Child_Staging {
return $value; return $value;
} }
} }