Fixed: CodeFactor issues

This commit is contained in:
Bogdan Rapaić 2020-04-20 19:00:37 +02:00 committed by GitHub
parent e91b1612c4
commit f5f8f6d920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,5 @@
<?php
/*
*
/**
* Credits
*
* Plugin-Name: Vulnerability Alerts
@ -22,7 +20,7 @@ class MainWP_Child_Vulnerability_Checker {
private $wpvulndb_api = 'https://wpvulndb.com/api/v3/';
private $wpvulndb_token = false;
static function Instance() {
public static function Instance() {
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Vulnerability_Checker();
}
@ -35,7 +33,6 @@ class MainWP_Child_Vulnerability_Checker {
public function action() {
$information = array();
if ( ! empty( $this->wpvulndb_token ) ) {
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
@ -49,7 +46,7 @@ class MainWP_Child_Vulnerability_Checker {
MainWP_Helper::write( $information );
}
function vulner_recheck() {
public function vulner_recheck() {
$result = array();
$force = ( isset( $_POST['force'] ) && ! empty( $_POST['force'] ) ) ? true : false;
$result['plugin'] = $this->check_plugins( $force );
@ -62,7 +59,7 @@ class MainWP_Child_Vulnerability_Checker {
return $information;
}
function check_plugins( $force = false ) {
public function check_plugins( $force = false ) {
$result = array();
$active_plugins = get_option( 'active_plugins' );
@ -81,7 +78,6 @@ class MainWP_Child_Vulnerability_Checker {
if ( $plug_vuln ) {
$plug_vuln = json_decode( $plug_vuln, true );
$plug_vuln_filter = $plug_vuln;
foreach ( $plug_vuln as $slug => $pl_data ) {
if ( isset( $pl_data['vulnerabilities'] ) && count( $pl_data['vulnerabilities'] ) > 0 ) {
$plug_vulner_data = array();
@ -92,7 +88,7 @@ class MainWP_Child_Vulnerability_Checker {
$plug_vulner_data[] = $vuln_data;
}
if ( count($plug_vulner_data) == 0 ) {
if ( 0 == count( $plug_vulner_data ) ) {
unset( $plug_vuln_filter[ $slug ] );
} else {
$plug_vuln_filter[ $slug ]['vulnerabilities'] = $plug_vulner_data;
@ -104,11 +100,10 @@ class MainWP_Child_Vulnerability_Checker {
}
}
if ( count($plug_vuln_filter) == 0 ) {
if ( 0 == count( $plug_vuln_filter ) ) {
continue;
}
$plug_vuln = json_encode( $plug_vuln_filter );
} else {
continue;
}
@ -118,7 +113,7 @@ class MainWP_Child_Vulnerability_Checker {
return $result;
}
function check_wp( $force = false ) {
public function check_wp( $force = false ) {
$wp_vuln = get_transient( 'mainwp_vulnche_trans_wp_json' );
$wp_version = str_replace( '.', '', get_bloginfo( 'version' ) );
if ( false === $wp_vuln || $force ) {
@ -128,7 +123,7 @@ class MainWP_Child_Vulnerability_Checker {
return $wp_vuln;
}
function check_themes( $force = false ) {
public function check_themes( $force = false ) {
require_once ABSPATH . 'wp-admin/includes/misc.php';
require_once ABSPATH . 'wp-admin/includes/theme.php';
@ -154,21 +149,17 @@ class MainWP_Child_Vulnerability_Checker {
$th_vuln_filter = $th_vuln;
foreach ( $th_vuln as $slug => $th_data ) {
if ( isset( $th_data['vulnerabilities'] ) && count( $th_data['vulnerabilities'] ) > 0 ) {
$th_vulner_data = array();
foreach ( $th_data['vulnerabilities'] as $vuln_data ) {
if ( empty( $vuln_data ) ) {
continue;
}
if ( isset( $vuln_data['fixed_in'] ) && version_compare( $th['version'], $vuln_data['fixed_in'] ) >= 0 ) {
continue;
}
$th_vulner_data[] = $vuln_data;
}
if ( count($th_vulner_data) == 0 ) {
if ( 0 == count( $th_vulner_data ) ) {
unset( $th_vuln_filter[ $slug ] );
} else {
$th_vuln_filter[ $slug ]['vulnerabilities'] = $th_vulner_data;
@ -177,16 +168,13 @@ class MainWP_Child_Vulnerability_Checker {
unset( $th_vuln_filter[ $slug ] );
}
}
if ( count($th_vuln_filter) == 0 ) {
if ( 0 == count( $th_vuln_filter ) ) {
continue;
}
$th_vuln = json_encode( $th_vuln_filter );
} else {
continue;
}
$result[ $th['id'] ]['vulner_data'] = $th_vuln;
$result[ $th['id'] ]['name'] = $th['name'];
$result[ $th['id'] ]['author'] = $th['author'];
@ -198,10 +186,8 @@ class MainWP_Child_Vulnerability_Checker {
}
function vulnche_get_content( $url ) {
public function vulnche_get_content( $url ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Authorization: Token token=' . $this->wpvulndb_token ) );
@ -212,15 +198,14 @@ class MainWP_Child_Vulnerability_Checker {
$info = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
if ( $output === false || $info != 200 ) {
if ( false === $output || 200 != $info ) {
$output = null;
}
return $output;
}
function get_random_user_agent() {
public function get_random_user_agent() {
$someUA = array(
'Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.0',
@ -242,4 +227,3 @@ class MainWP_Child_Vulnerability_Checker {
}