woothemes/woocommerce

View on GitHub
includes/class-wc-regenerate-images.php

Summary

Maintainability
D
1 day
Test Coverage

Function maybe_resize_image has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    public static function maybe_resize_image( $image, $attachment_id, $size, $icon ) {
        if ( ! apply_filters( 'woocommerce_resize_images', true ) ) {
            return $image;
        }

Severity: Minor
Found in includes/class-wc-regenerate-images.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

File class-wc-regenerate-images.php has 253 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Regenerate Images Functionality
 *
 * All functionality pertaining to regenerating product images in realtime.
Severity: Minor
Found in includes/class-wc-regenerate-images.php - About 2 hrs to fix

    Method resize_and_return_image has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static function resize_and_return_image( $attachment_id, $image, $size, $icon ) {
            if ( ! self::is_regeneratable( $attachment_id ) ) {
                return $image;
            }
    
    
    Severity: Minor
    Found in includes/class-wc-regenerate-images.php - About 1 hr to fix

      Method maybe_resize_image has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function maybe_resize_image( $image, $attachment_id, $size, $icon ) {
              if ( ! apply_filters( 'woocommerce_resize_images', true ) ) {
                  return $image;
              }
      
      
      Severity: Minor
      Found in includes/class-wc-regenerate-images.php - About 1 hr to fix

        Function resize_and_return_image has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            private static function resize_and_return_image( $attachment_id, $image, $size, $icon ) {
                if ( ! self::is_regeneratable( $attachment_id ) ) {
                    return $image;
                }
        
        
        Severity: Minor
        Found in includes/class-wc-regenerate-images.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 filter_image_get_intermediate_size has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function filter_image_get_intermediate_size( $data, $attachment_id, $size ) {
                if ( ! is_string( $size ) || ! in_array( $size, apply_filters( 'woocommerce_image_sizes_to_resize', array( 'woocommerce_thumbnail', 'woocommerce_gallery_thumbnail', 'woocommerce_single', 'shop_thumbnail', 'shop_catalog', 'shop_single' ) ), true ) ) {
                    return $data;
                }
        
        
        Severity: Minor
        Found in includes/class-wc-regenerate-images.php - About 45 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 image_size_matches_settings has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            protected static function image_size_matches_settings( $image, $size ) {
                $target_size = wc_get_image_size( $size );
                $uncropped   = '' === $target_size['width'] || '' === $target_size['height'];
        
                if ( ! $uncropped ) {
        Severity: Minor
        Found in includes/class-wc-regenerate-images.php - About 45 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

        Avoid too many return statements within this method.
        Open

                return $data;
        Severity: Major
        Found in includes/class-wc-regenerate-images.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return $new_image ? $new_image : $image;
          Severity: Major
          Found in includes/class-wc-regenerate-images.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return $image;
            Severity: Major
            Found in includes/class-wc-regenerate-images.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return $image;
              Severity: Major
              Found in includes/class-wc-regenerate-images.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return $image;
                Severity: Major
                Found in includes/class-wc-regenerate-images.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return $image;
                  Severity: Major
                  Found in includes/class-wc-regenerate-images.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return self::resize_and_return_image( $attachment_id, $image, $size, $icon );
                    Severity: Major
                    Found in includes/class-wc-regenerate-images.php - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status