File class-wc-admin-dashboard.php
has 388 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Admin Dashboard
*
* @package WooCommerce\Admin
Method status_widget_stock_rows
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function status_widget_stock_rows( $is_wc_admin_disabled ) {
global $wpdb;
// Requires lookup table added in 3.6.
if ( version_compare( get_option( 'woocommerce_db_version', null ), '3.6', '<' ) ) {
Method network_orders
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function network_orders() {
$suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
$version = Constants::get_constant( 'WC_VERSION' );
wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), $version );
Method status_widget
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function status_widget() {
$suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
$version = Constants::get_constant( 'WC_VERSION' );
wp_enqueue_script( 'wc-status-widget', WC()->plugin_url() . '/assets/js/admin/wc-status-widget' . $suffix . '.js', array( 'jquery' ), $version, true );
Function status_widget_stock_rows
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function status_widget_stock_rows( $is_wc_admin_disabled ) {
global $wpdb;
// Requires lookup table added in 3.6.
if ( version_compare( get_option( 'woocommerce_db_version', null ), '3.6', '<' ) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method sales_sparkline
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function sales_sparkline( $reports, $is_wc_admin_disabled = false, $id = '', $type = 'sales' ) {
$days = max( 7, gmdate( 'd', current_time( 'timestamp' ) ) );
if ( $is_wc_admin_disabled ) {
return $reports->sales_sparkline( $id, $days, $type );
}
Method status_widget_order_rows
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function status_widget_order_rows() {
if ( ! current_user_can( 'edit_shop_orders' ) ) {
return;
}
$on_hold_count = 0;
Function status_widget
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function status_widget() {
$suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
$version = Constants::get_constant( 'WC_VERSION' );
wp_enqueue_script( 'wc-status-widget', WC()->plugin_url() . '/assets/js/admin/wc-status-widget' . $suffix . '.js', array( 'jquery' ), $version, true );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function sales_sparkline
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function sales_sparkline( $reports, $is_wc_admin_disabled = false, $id = '', $type = 'sales' ) {
$days = max( 7, gmdate( 'd', current_time( 'timestamp' ) ) );
if ( $is_wc_admin_disabled ) {
return $reports->sales_sparkline( $id, $days, $type );
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method recent_reviews
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function recent_reviews() {
global $wpdb;
$query_from = apply_filters(
'woocommerce_report_recent_reviews_query_from',
Method get_wc_admin_performance_data
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function get_wc_admin_performance_data() {
$request = new \WP_REST_Request( 'GET', '/wc-analytics/reports/performance-indicators' );
$start_date = gmdate( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
$end_date = gmdate( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
$request->set_query_params(
Function get_wc_admin_performance_data
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function get_wc_admin_performance_data() {
$request = new \WP_REST_Request( 'GET', '/wc-analytics/reports/performance-indicators' );
$start_date = gmdate( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
$end_date = gmdate( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
$request->set_query_params(
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function __construct
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function __construct() {
// Only hook in admin parts if the user has admin access.
if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) {
// If on network admin, only load the widget that works in that context and skip the rest.
if ( is_multisite() && is_network_admin() ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function recent_reviews
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function recent_reviews() {
global $wpdb;
$query_from = apply_filters(
'woocommerce_report_recent_reviews_query_from',
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ( 'sales' === $type ) {
/* translators: 1: total income 2: days */
$tooltip = sprintf( __( 'Sold %1$s worth in the last %2$d days', 'woocommerce' ), strip_tags( wc_price( $total ) ), $days );
} else {
/* translators: 1: total items sold 2: days */
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 92.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76