| @@ -6,132 +6,136 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace MainWP\Dashboard; |
| 9 | 9 | |
| 10 | +// Exit if accessed directly. | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 10 | 15 | /** |
| 11 | 16 | * Class MainWP_Reports_Helper. |
| 12 | 17 | * |
| 13 | 18 | * @package MainWP\Dashboard |
| 14 | 19 | */ |
| 15 | -class MainWP_Reports_Helper { | |
| 20 | +class MainWP_Reports_Helper { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 16 | 21 | |
| 17 | - /** | |
| 18 | - * Reports sites values | |
| 19 | - * | |
| 20 | - * @static | |
| 21 | - * @var array $reports_sites_values array values. | |
| 22 | - */ | |
| 23 | - private static $reports_sites_values = array(); | |
| 22 | + /** | |
| 23 | + * Reports sites values | |
| 24 | + * | |
| 25 | + * @static | |
| 26 | + * @var array $reports_sites_values array values. | |
| 27 | + */ | |
| 28 | + private static $reports_sites_values = array(); | |
| 24 | 29 | |
| 25 | - /** | |
| 26 | - * Protected static variable to hold the instance. | |
| 27 | - * | |
| 28 | - * @var null Default value. | |
| 29 | - */ | |
| 30 | - private static $instance = null; | |
| 30 | + /** | |
| 31 | + * Protected static variable to hold the instance. | |
| 32 | + * | |
| 33 | + * @var null Default value. | |
| 34 | + */ | |
| 35 | + private static $instance = null; | |
| 31 | 36 | |
| 32 | - /** | |
| 33 | - * Create Instance. | |
| 34 | - * | |
| 35 | - * @return self $instance | |
| 36 | - */ | |
| 37 | - public static function get_instance() { | |
| 38 | - if ( null === self::$instance ) { | |
| 39 | - self::$instance = new self(); | |
| 40 | - } | |
| 41 | - return self::$instance; | |
| 42 | - } | |
| 37 | + /** | |
| 38 | + * Create Instance. | |
| 39 | + * | |
| 40 | + * @return self $instance | |
| 41 | + */ | |
| 42 | + public static function get_instance() { | |
| 43 | + if ( null === static::$instance ) { | |
| 44 | + static::$instance = new self(); | |
| 45 | + } | |
| 46 | + return static::$instance; | |
| 47 | + } | |
| 43 | 48 | |
| 44 | - /** | |
| 45 | - * Construct method. | |
| 46 | - */ | |
| 47 | - public function __construct() { | |
| 48 | - // construct. | |
| 49 | - } | |
| 49 | + /** | |
| 50 | + * Construct method. | |
| 51 | + */ | |
| 52 | + public function __construct() { | |
| 53 | + // construct. | |
| 54 | + } | |
| 50 | 55 | |
| 51 | 56 | |
| 52 | - /** | |
| 53 | - * Method hook_get_reports_group_values() | |
| 54 | - * | |
| 55 | - * Get dashboard tokens values for reports. | |
| 56 | - * | |
| 57 | - * @param array $values Input values. | |
| 58 | - * @param string $group Group tokens. | |
| 59 | - * @param array $types Types of tokens. | |
| 60 | - * @param int $site_id Site ID. | |
| 61 | - */ | |
| 62 | - public function hook_get_reports_group_values( $values, $group, $types, $site_id ) { | |
| 63 | - if ( ! is_array( $values ) ) { | |
| 64 | - $values = array(); | |
| 65 | - } | |
| 57 | + /** | |
| 58 | + * Method hook_get_reports_group_values() | |
| 59 | + * | |
| 60 | + * Get dashboard tokens values for reports. | |
| 61 | + * | |
| 62 | + * @param array $values Input values. | |
| 63 | + * @param string $group Group tokens. | |
| 64 | + * @param array $types Types of tokens. | |
| 65 | + * @param int $site_id Site ID. | |
| 66 | + */ | |
| 67 | + public function hook_get_reports_group_values( $values, $group, $types, $site_id ) { // phpcs:ignore -- NOSONAR - complex. | |
| 68 | + if ( ! is_array( $values ) ) { | |
| 69 | + $values = array(); | |
| 70 | + } | |
| 66 | 71 | |
| 67 | - if ( ! isset( self::$reports_sites_values[ $site_id ] ) ) { | |
| 68 | - self::$reports_sites_values[ $site_id ] = $this->get_group_reports_data_of_site( $site_id ); | |
| 69 | - } | |
| 72 | + if ( ! isset( static::$reports_sites_values[ $site_id ] ) ) { | |
| 73 | + static::$reports_sites_values[ $site_id ] = $this->get_group_reports_data_of_site( $site_id ); | |
| 74 | + } | |
| 70 | 75 | |
| 71 | - if ( empty( $group ) && empty( $types ) ) { | |
| 72 | - return isset( self::$reports_sites_values[ $site_id ] ) ? self::$reports_sites_values[ $site_id ] : array(); | |
| 73 | - } | |
| 76 | + if ( empty( $group ) && empty( $types ) ) { | |
| 77 | + return isset( static::$reports_sites_values[ $site_id ] ) ? static::$reports_sites_values[ $site_id ] : array(); | |
| 78 | + } | |
| 74 | 79 | |
| 75 | - if ( ! empty( $group ) && empty( $types ) ) { | |
| 76 | - $values[ $group ] = isset( self::$reports_sites_values[ $site_id ][ $group ] ) ? self::$reports_sites_values[ $site_id ][ $group ] : array(); | |
| 77 | - return $values; | |
| 78 | - } | |
| 80 | + if ( ! empty( $group ) && empty( $types ) ) { | |
| 81 | + $values[ $group ] = isset( static::$reports_sites_values[ $site_id ][ $group ] ) ? static::$reports_sites_values[ $site_id ][ $group ] : array(); | |
| 82 | + return $values; | |
| 83 | + } | |
| 79 | 84 | |
| 80 | - if ( ! empty( $group ) && is_array( $types ) ) { | |
| 81 | - foreach ( $types as $type ) { | |
| 82 | - $values[ $group ][ $type ] = isset( self::$reports_sites_values[ $site_id ][ $group ][ $type ] ) ? self::$reports_sites_values[ $site_id ][ $group ][ $type ] : array(); | |
| 83 | - } | |
| 84 | - } | |
| 85 | + if ( ! empty( $group ) && is_array( $types ) ) { | |
| 86 | + foreach ( $types as $type ) { | |
| 87 | + $values[ $group ][ $type ] = isset( static::$reports_sites_values[ $site_id ][ $group ][ $type ] ) ? static::$reports_sites_values[ $site_id ][ $group ][ $type ] : array(); | |
| 88 | + } | |
| 89 | + } | |
| 85 | 90 | |
| 86 | - return $values; | |
| 87 | - } | |
| 91 | + return $values; | |
| 92 | + } | |
| 88 | 93 | |
| 89 | - /** | |
| 90 | - * Get tokens values of site. | |
| 91 | - * | |
| 92 | - * @param int $site_id Site ID. | |
| 93 | - */ | |
| 94 | - public function get_group_reports_data_of_site( $site_id ) { | |
| 94 | + /** | |
| 95 | + * Get tokens values of site. | |
| 96 | + * | |
| 97 | + * @param int $site_id Site ID. | |
| 98 | + */ | |
| 99 | + public function get_group_reports_data_of_site( $site_id ) { | |
| 95 | 100 | |
| 96 | - $website = MainWP_DB::instance()->get_website_by_id( $site_id ); | |
| 101 | + $website = MainWP_DB::instance()->get_website_by_id( $site_id ); | |
| 97 | 102 | |
| 98 | - $abandoned_plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' ); | |
| 99 | - $abandoned_plugins = ! empty( $abandoned_plugins ) ? json_decode( $abandoned_plugins, true ) : array(); | |
| 103 | + $abandoned_plugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' ); | |
| 104 | + $abandoned_plugins = ! empty( $abandoned_plugins ) ? json_decode( $abandoned_plugins, true ) : array(); | |
| 100 | 105 | |
| 101 | - if ( ! is_array( $abandoned_plugins ) ) { | |
| 102 | - $abandoned_plugins = array(); | |
| 103 | - } | |
| 106 | + if ( ! is_array( $abandoned_plugins ) ) { | |
| 107 | + $abandoned_plugins = array(); | |
| 108 | + } | |
| 104 | 109 | |
| 105 | - $abandoned_themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' ); | |
| 106 | - $abandoned_themes = ! empty( $abandoned_themes ) ? json_decode( $abandoned_themes, true ) : array(); | |
| 110 | + $abandoned_themes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' ); | |
| 111 | + $abandoned_themes = ! empty( $abandoned_themes ) ? json_decode( $abandoned_themes, true ) : array(); | |
| 107 | 112 | |
| 108 | - if ( ! is_array( $abandoned_themes ) ) { | |
| 109 | - $abandoned_themes = array(); | |
| 110 | - } | |
| 113 | + if ( ! is_array( $abandoned_themes ) ) { | |
| 114 | + $abandoned_themes = array(); | |
| 115 | + } | |
| 111 | 116 | |
| 112 | - $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' ); | |
| 113 | - $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array(); | |
| 117 | + $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' ); | |
| 118 | + $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array(); | |
| 114 | 119 | |
| 115 | - $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 116 | - $theme_upgrades = json_decode( $website->theme_upgrades, true ); | |
| 117 | - $translation_upgrades = json_decode( $website->translation_upgrades, true ); | |
| 120 | + $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 121 | + $theme_upgrades = json_decode( $website->theme_upgrades, true ); | |
| 122 | + $translation_upgrades = json_decode( $website->translation_upgrades, true ); | |
| 118 | 123 | |
| 119 | - $results = array( | |
| 120 | - 'plugins' => array( | |
| 121 | - 'abandoned' => $abandoned_plugins, | |
| 122 | - 'pending' => $plugin_upgrades, | |
| 123 | - ), | |
| 124 | - 'themes' => array( | |
| 125 | - 'abandoned' => $abandoned_themes, | |
| 126 | - 'pending' => $theme_upgrades, | |
| 127 | - ), | |
| 128 | - 'wordpress' => array( // phpcs:ignore -- wordpress. | |
| 129 | - 'pending' => array( 'wordpress' => $wp_upgrades ), // phpcs:ignore -- wordpress. | |
| 130 | - ), | |
| 131 | - 'translation' => array( | |
| 132 | - 'pending' => $translation_upgrades, | |
| 133 | - ), | |
| 134 | - ); | |
| 135 | - return $results; | |
| 136 | - } | |
| 124 | + return array( | |
| 125 | + 'plugins' => array( | |
| 126 | + 'abandoned' => $abandoned_plugins, | |
| 127 | + 'pending' => $plugin_upgrades, | |
| 128 | + ), | |
| 129 | + 'themes' => array( | |
| 130 | + 'abandoned' => $abandoned_themes, | |
| 131 | + 'pending' => $theme_upgrades, | |
| 132 | + ), | |
| 133 | + 'wordpress' => array( // phpcs:ignore -- wordpress. | |
| 134 | + 'pending' => array( 'wordpress' => $wp_upgrades ), // phpcs:ignore -- wordpress. | |
| 135 | + ), | |
| 136 | + 'translation' => array( | |
| 137 | + 'pending' => $translation_upgrades, | |
| 138 | + ), | |
| 139 | + ); | |
| 140 | + } | |
| 137 | 141 | } |