| Conditions | 6 |
| Paths | 4 |
| Total Lines | 86 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 30 | public function get_database_info() { |
||
| 31 | global $wpdb; |
||
| 32 | |||
| 33 | $database_table_information = $wpdb->get_results( |
||
| 34 | $wpdb->prepare( |
||
| 35 | "SELECT |
||
| 36 | table_name AS 'name', |
||
| 37 | engine, |
||
| 38 | round( ( data_length / 1024 / 1024 ), 2 ) 'data', |
||
| 39 | round( ( index_length / 1024 / 1024 ), 2 ) 'index' |
||
| 40 | FROM information_schema.TABLES |
||
| 41 | WHERE table_schema = %s |
||
| 42 | ORDER BY name ASC;", |
||
| 43 | DB_NAME |
||
| 44 | ) |
||
| 45 | ); |
||
| 46 | |||
| 47 | // WC Core tables to check existence of. |
||
| 48 | $core_tables = apply_filters( |
||
| 49 | 'woocommerce_database_tables', |
||
| 50 | array( |
||
| 51 | 'woocommerce_sessions', |
||
| 52 | 'woocommerce_api_keys', |
||
| 53 | 'woocommerce_attribute_taxonomies', |
||
| 54 | 'woocommerce_downloadable_product_permissions', |
||
| 55 | 'woocommerce_order_items', |
||
| 56 | 'woocommerce_order_itemmeta', |
||
| 57 | 'woocommerce_tax_rates', |
||
| 58 | 'woocommerce_tax_rate_locations', |
||
| 59 | 'woocommerce_shipping_zones', |
||
| 60 | 'woocommerce_shipping_zone_locations', |
||
| 61 | 'woocommerce_shipping_zone_methods', |
||
| 62 | 'woocommerce_payment_tokens', |
||
| 63 | 'woocommerce_payment_tokenmeta', |
||
| 64 | 'woocommerce_log', |
||
| 65 | ) |
||
| 66 | ); |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Adding the prefix to the tables array, for backwards compatibility. |
||
| 70 | * |
||
| 71 | * If we changed the tables above to include the prefix, then any filters against that table could break. |
||
| 72 | */ |
||
| 73 | $core_tables = array_map( array( $this, 'add_db_table_prefix' ), $core_tables ); |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Organize WooCommerce and non-WooCommerce tables separately for display purposes later. |
||
| 77 | * |
||
| 78 | * To ensure we include all WC tables, even if they do not exist, pre-populate the WC array with all the tables. |
||
| 79 | */ |
||
| 80 | $tables = array( |
||
| 81 | 'woocommerce' => array_fill_keys( $core_tables, false ), |
||
| 82 | 'other' => array(), |
||
| 83 | ); |
||
| 84 | |||
| 85 | $database_size = array( |
||
| 86 | 'data' => 0, |
||
| 87 | 'index' => 0, |
||
| 88 | ); |
||
| 89 | |||
| 90 | $site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() ); |
||
| 91 | $global_tables = $wpdb->tables( 'global', true ); |
||
| 92 | foreach ( $database_table_information as $table ) { |
||
| 93 | // Only include tables matching the prefix of the current site, this is to prevent displaying all tables on a MS install not relating to the current. |
||
| 94 | if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | $table_type = in_array( $table->name, $core_tables, true ) ? 'woocommerce' : 'other'; |
||
| 98 | |||
| 99 | $tables[ $table_type ][ $table->name ] = array( |
||
| 100 | 'data' => $table->data, |
||
| 101 | 'index' => $table->index, |
||
| 102 | 'engine' => $table->engine, |
||
| 103 | ); |
||
| 104 | |||
| 105 | $database_size['data'] += $table->data; |
||
| 106 | $database_size['index'] += $table->index; |
||
| 107 | } |
||
| 108 | |||
| 109 | // Return all database info. Described by JSON Schema. |
||
| 110 | return array( |
||
| 111 | 'wc_database_version' => get_option( 'woocommerce_db_version' ), |
||
| 112 | 'database_prefix' => $wpdb->prefix, |
||
| 113 | 'maxmind_geoip_database' => \WC_Geolocation::get_local_database_path(), |
||
| 114 | 'database_tables' => $tables, |
||
| 115 | 'database_size' => $database_size, |
||
| 116 | ); |
||
| 119 |