woothemes/woocommerce

View on GitHub
includes/abstracts/abstract-wc-product.php

Summary

Maintainability
F
5 days
Test Coverage

WC_Product has 158 functions (exceeds 20 allowed). Consider refactoring.
Open

class WC_Product extends WC_Abstract_Legacy_Product {

    /**
     * This is the name of this object type.
     *
Severity: Major
Found in includes/abstracts/abstract-wc-product.php - About 3 days to fix

    File abstract-wc-product.php has 794 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * WooCommerce product base class.
     *
     * @package WooCommerce\Abstracts
    Severity: Major
    Found in includes/abstracts/abstract-wc-product.php - About 1 day to fix

      Function set_downloads has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          public function set_downloads( $downloads_array ) {
              $downloads = array();
              $errors    = array();
      
              foreach ( $downloads_array as $download ) {
      Severity: Minor
      Found in includes/abstracts/abstract-wc-product.php - About 2 hrs to fix

      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 set_downloads has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function set_downloads( $downloads_array ) {
              $downloads = array();
              $errors    = array();
      
              foreach ( $downloads_array as $download ) {
      Severity: Minor
      Found in includes/abstracts/abstract-wc-product.php - About 1 hr to fix

        Function is_visible_core has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function is_visible_core() {
                $visible = 'visible' === $this->get_catalog_visibility() || ( is_search() && 'search' === $this->get_catalog_visibility() ) || ( ! is_search() && 'catalog' === $this->get_catalog_visibility() );
        
                if ( 'trash' === $this->get_status() ) {
                    $visible = false;
        Severity: Minor
        Found in includes/abstracts/abstract-wc-product.php - About 1 hr to fix

        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 is_on_sale has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public function is_on_sale( $context = 'view' ) {
                if ( '' !== (string) $this->get_sale_price( $context ) && $this->get_regular_price( $context ) > $this->get_sale_price( $context ) ) {
                    $on_sale = true;
        
                    if ( $this->get_date_on_sale_from( $context ) && $this->get_date_on_sale_from( $context )->getTimestamp() > time() ) {
        Severity: Minor
        Found in includes/abstracts/abstract-wc-product.php - About 35 mins to fix

        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 get_availability_text has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function get_availability_text() {
                if ( ! $this->is_in_stock() ) {
                    $availability = __( 'Out of stock', 'woocommerce' );
                } elseif ( $this->managing_stock() && $this->is_on_backorder( 1 ) ) {
                    $availability = $this->backorders_require_notification() ? __( 'Available on backorder', 'woocommerce' ) : '';
        Severity: Minor
        Found in includes/abstracts/abstract-wc-product.php - About 25 mins to fix

        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 get_image has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            public function get_image( $size = 'woocommerce_thumbnail', $attr = array(), $placeholder = true ) {
                $image = '';
                if ( $this->get_image_id() ) {
                    $image = wp_get_attachment_image( $this->get_image_id(), $size, false, $attr );
                } elseif ( $this->get_parent_id() ) {
        Severity: Minor
        Found in includes/abstracts/abstract-wc-product.php - About 25 mins to fix

        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 6 (exceeds 5 allowed). Consider refactoring.
        Open

            public function __construct( $product = 0 ) {
                parent::__construct( $product );
                if ( is_numeric( $product ) && $product > 0 ) {
                    $this->set_id( $product );
                } elseif ( $product instanceof self ) {
        Severity: Minor
        Found in includes/abstracts/abstract-wc-product.php - About 25 mins to fix

        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 get_availability_class has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function get_availability_class() {
                if ( ! $this->is_in_stock() ) {
                    $class = 'out-of-stock';
                } elseif ( ( $this->managing_stock() && $this->is_on_backorder( 1 ) ) || ( ! $this->managing_stock() && $this->is_on_backorder( 1 ) ) ) {
                    $class = 'available-on-backorder';
        Severity: Minor
        Found in includes/abstracts/abstract-wc-product.php - About 25 mins to fix

        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

        There are no issues that match your filters.

        Category
        Status