woothemes/woocommerce

View on GitHub
includes/admin/class-wc-admin-addons.php

Summary

Maintainability
F
3 days
Test Coverage

File class-wc-admin-addons.php has 528 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Addons Page
 *
 * @package  WooCommerce\Admin
Severity: Major
Found in includes/admin/class-wc-admin-addons.php - About 1 day to fix

    Method output_wcs_banner_block has 94 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function output_wcs_banner_block( $block = array() ) {
            $is_active = is_plugin_active( 'woocommerce-services/woocommerce-services.php' );
            $location  = wc_get_base_location();
    
            if (
    Severity: Major
    Found in includes/admin/class-wc-admin-addons.php - About 3 hrs to fix

      WC_Admin_Addons has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class WC_Admin_Addons {
      
          /**
           * Get featured for the addons screen
           *
      Severity: Minor
      Found in includes/admin/class-wc-admin-addons.php - About 2 hrs to fix

        Method output_wcpay_banner_block has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function output_wcpay_banner_block( $block = array() ) {
                $is_active = is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' );
                $location  = wc_get_base_location();
        
                if (
        Severity: Minor
        Found in includes/admin/class-wc-admin-addons.php - About 2 hrs to fix

          Method output has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function output() {
                  $section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '_featured';
                  $search  = isset( $_GET['search'] ) ? sanitize_text_field( wp_unslash( $_GET['search'] ) ) : '';
          
                  if ( isset( $_GET['section'] ) && 'helper' === $_GET['section'] ) {
          Severity: Minor
          Found in includes/admin/class-wc-admin-addons.php - About 1 hr to fix

            Method output_featured_sections has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function output_featured_sections( $sections ) {
                    foreach ( $sections as $section ) {
                        switch ( $section->module ) {
                            case 'banner_block':
                                self::output_banner_block( $section );
            Severity: Minor
            Found in includes/admin/class-wc-admin-addons.php - About 1 hr to fix

              Method output_banner_block has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function output_banner_block( $block ) {
                      ?>
                      <div class="addons-banner-block">
                          <h1><?php echo esc_html( $block->title ); ?></h1>
                          <p><?php echo esc_html( $block->description ); ?></p>
              Severity: Minor
              Found in includes/admin/class-wc-admin-addons.php - About 1 hr to fix

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

                    public static function output_featured_sections( $sections ) {
                        foreach ( $sections as $section ) {
                            switch ( $section->module ) {
                                case 'banner_block':
                                    self::output_banner_block( $section );
                Severity: Minor
                Found in includes/admin/class-wc-admin-addons.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 get_section_data has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function get_section_data( $section_id ) {
                        $section      = self::get_section( $section_id );
                        $section_data = '';
                
                        if ( ! empty( $section->endpoint ) ) {
                Severity: Minor
                Found in includes/admin/class-wc-admin-addons.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

                Method output_storefront_button has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function output_storefront_button() {
                        $template   = get_option( 'template' );
                        $stylesheet = get_option( 'stylesheet' );
                
                        if ( 'storefront' === $template ) {
                Severity: Minor
                Found in includes/admin/class-wc-admin-addons.php - About 1 hr to fix

                  Method output_column_block has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function output_column_block( $block ) {
                          ?>
                          <div class="addons-column-block">
                              <h1><?php echo esc_html( $block->title ); ?></h1>
                              <p><?php echo esc_html( $block->description ); ?></p>
                  Severity: Minor
                  Found in includes/admin/class-wc-admin-addons.php - About 1 hr to fix

                    Function get_featured has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function get_featured() {
                            $featured = get_transient( 'wc_addons_featured' );
                            if ( false === $featured ) {
                                $headers = array();
                                $auth    = WC_Helper_Options::get( 'auth' );
                    Severity: Minor
                    Found in includes/admin/class-wc-admin-addons.php - About 55 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 output has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function output() {
                            $section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '_featured';
                            $search  = isset( $_GET['search'] ) ? sanitize_text_field( wp_unslash( $_GET['search'] ) ) : '';
                    
                            if ( isset( $_GET['section'] ) && 'helper' === $_GET['section'] ) {
                    Severity: Minor
                    Found in includes/admin/class-wc-admin-addons.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 get_sections has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function get_sections() {
                            $addon_sections = get_transient( 'wc_addons_sections' );
                            if ( false === ( $addon_sections ) ) {
                                $raw_sections = wp_safe_remote_get(
                                    'https://woocommerce.com/wp-json/wccom-extensions/1.0/categories'
                    Severity: Minor
                    Found in includes/admin/class-wc-admin-addons.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 output_wcs_banner_block has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function output_wcs_banner_block( $block = array() ) {
                            $is_active = is_plugin_active( 'woocommerce-services/woocommerce-services.php' );
                            $location  = wc_get_base_location();
                    
                            if (
                    Severity: Minor
                    Found in includes/admin/class-wc-admin-addons.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 output_column has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function output_column( $block ) {
                            if ( isset( $block->container ) && 'column_container_start' === $block->container ) {
                                ?>
                                <div class="addons-column-section">
                                <?php
                    Severity: Minor
                    Found in includes/admin/class-wc-admin-addons.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

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            $defaults = array(
                                'image'       => WC()->plugin_url() . '/assets/images/wcpayments-icon-secure.png',
                                'image_alt'   => __( 'WooCommerce Payments', 'woocommerce' ),
                                'title'       => __( 'Payments made simple, with no monthly fees &mdash; exclusively for WooCommerce stores.', 'woocommerce' ),
                                'description' => __( 'Securely accept cards in your store. See payments, track cash flow into your bank account, and stay on top of disputes – right from your dashboard.', 'woocommerce' ),
                    Severity: Minor
                    Found in includes/admin/class-wc-admin-addons.php and 1 other location - About 45 mins to fix
                    includes/admin/class-wc-admin-addons.php on lines 395..403

                    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 95.

                    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

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            $defaults = array(
                                'image'       => WC()->plugin_url() . '/assets/images/wcs-extensions-banner-3x.png',
                                'image_alt'   => __( 'WooCommerce Shipping', 'woocommerce' ),
                                'title'       => __( 'Buy discounted shipping labels — then print them from your dashboard.', 'woocommerce' ),
                                'description' => __( 'Integrate your store with USPS to buy discounted shipping labels, and print them directly from your WooCommerce dashboard. Powered by WooCommerce Shipping.', 'woocommerce' ),
                    Severity: Minor
                    Found in includes/admin/class-wc-admin-addons.php and 1 other location - About 45 mins to fix
                    includes/admin/class-wc-admin-addons.php on lines 502..510

                    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 95.

                    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

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status