woocommerce/woocommerce

View on GitHub
includes/emails/class-wc-email.php

Summary

Maintainability
F
3 days
Test Coverage

File class-wc-email.php has 541 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Class WC_Email file.
 *
 * @package WooCommerce\Emails
Severity: Major
Found in includes/emails/class-wc-email.php - About 1 day to fix

    WC_Email has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WC_Email extends WC_Settings_API {
    
        /**
         * Email method ID.
         *
    Severity: Minor
    Found in includes/emails/class-wc-email.php - About 5 hrs to fix

      Method admin_options has 124 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function admin_options() {
              // Do admin actions.
              $this->admin_actions();
              ?>
              <h2><?php echo esc_html( $this->get_title() ); ?> <?php wc_back_link( __( 'Return to emails', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=email' ) ); ?></h2>
      Severity: Major
      Found in includes/emails/class-wc-email.php - About 4 hrs to fix

        Function admin_options has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
        Open

            public function admin_options() {
                // Do admin actions.
                $this->admin_actions();
                ?>
                <h2><?php echo esc_html( $this->get_title() ); ?> <?php wc_back_link( __( 'Return to emails', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=email' ) ); ?></h2>
        Severity: Minor
        Found in includes/emails/class-wc-email.php - About 4 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

        Function admin_actions has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function admin_actions() {
                // Handle any actions.
                if (
                    ( ! empty( $this->template_html ) || ! empty( $this->template_plain ) )
                    && ( ! empty( $_GET['move_template'] ) || ! empty( $_GET['delete_template'] ) )
        Severity: Minor
        Found in includes/emails/class-wc-email.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 init_form_fields has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function init_form_fields() {
                /* translators: %s: list of placeholders */
                $placeholder_text  = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
                $this->form_fields = array(
                    'enabled'            => array(
        Severity: Minor
        Found in includes/emails/class-wc-email.php - About 1 hr to fix

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

              protected function save_template( $template_code, $template_path ) {
                  if ( current_user_can( 'edit_themes' ) && ! empty( $template_code ) && ! empty( $template_path ) ) {
                      $saved = false;
                      $file  = get_stylesheet_directory() . '/' . WC()->template_path() . $template_path;
                      $code  = wp_unslash( $template_code );
          Severity: Minor
          Found in includes/emails/class-wc-email.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 style_inline has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function style_inline( $content ) {
                  if ( in_array( $this->get_content_type(), array( 'text/html', 'multipart/alternative' ), true ) ) {
                      ob_start();
                      wc_get_template( 'emails/email-styles.php' );
                      $css = apply_filters( 'woocommerce_email_styles', ob_get_clean(), $this );
          Severity: Minor
          Found in includes/emails/class-wc-email.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

          Method send has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function send( $to, $subject, $message, $headers, $attachments ) {
          Severity: Minor
          Found in includes/emails/class-wc-email.php - About 35 mins to fix

            Function get_headers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_headers() {
                    $header = 'Content-Type: ' . $this->get_content_type() . "\r\n";
            
                    if ( in_array( $this->id, array( 'new_order', 'cancelled_order', 'failed_order' ), true ) ) {
                        if ( $this->object && $this->object->get_billing_email() && ( $this->object->get_billing_first_name() || $this->object->get_billing_last_name() ) ) {
            Severity: Minor
            Found in includes/emails/class-wc-email.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 delete_template_action has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function delete_template_action( $template_type ) {
                    $template = $this->get_template( $template_type );
            
                    if ( $template ) {
                        if ( ! empty( $template ) ) {
            Severity: Minor
            Found in includes/emails/class-wc-email.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