connectors/class-connector-widgets.php

Summary

Maintainability
F
1 wk
Test Coverage
F
6%

File class-connector-widgets.php has 472 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Connector for Widgets
 *
 * @package WP_Stream
Severity: Minor
Found in connectors/class-connector-widgets.php - About 7 hrs to fix

    Function callback_updated_option has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        public function callback_updated_option( $option_name, $old_value, $new_value ) {
            if ( ! preg_match( '/^widget_(.+)$/', $option_name, $matches ) || ! is_array( $new_value ) ) {
                return;
            }
    
    
    Severity: Minor
    Found in connectors/class-connector-widgets.php - About 5 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 callback_updated_option has 116 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function callback_updated_option( $option_name, $old_value, $new_value ) {
            if ( ! preg_match( '/^widget_(.+)$/', $option_name, $matches ) || ! is_array( $new_value ) ) {
                return;
            }
    
    
    Severity: Major
    Found in connectors/class-connector-widgets.php - About 4 hrs to fix

      Function handle_widget_moved has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function handle_widget_moved( $old, $new ) {
              $all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
      
              foreach ( $all_sidebar_ids as $new_sidebar_id ) {
                  if ( $old[ $new_sidebar_id ] === $new[ $new_sidebar_id ] ) {
      Severity: Minor
      Found in connectors/class-connector-widgets.php - About 3 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

      Connector_Widgets has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Connector_Widgets extends Connector {
      
          /**
           * Whether or not 'created' and 'deleted' actions should be logged. Normally
           * the sidebar 'added' and 'removed' actions will correspond with these.
      Severity: Minor
      Found in connectors/class-connector-widgets.php - About 2 hrs to fix

        Method handle_widget_moved has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function handle_widget_moved( $old, $new ) {
                $all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
        
                foreach ( $all_sidebar_ids as $new_sidebar_id ) {
                    if ( $old[ $new_sidebar_id ] === $new[ $new_sidebar_id ] ) {
        Severity: Minor
        Found in connectors/class-connector-widgets.php - About 1 hr to fix

          Function handle_reactivated_widgets has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function handle_reactivated_widgets( $old, $new ) {
                  $new_reactivated_widget_ids = array_diff( $old['wp_inactive_widgets'], $new['wp_inactive_widgets'] );
          
                  foreach ( $new_reactivated_widget_ids as $widget_id ) {
                      $sidebar_id = '';
          Severity: Minor
          Found in connectors/class-connector-widgets.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 handle_widget_addition has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function handle_widget_addition( $old, $new ) {
                  $all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
                  $all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
                  $added_widget_ids   = array_diff( $all_new_widget_ids, $all_old_widget_ids );
          
          
          Severity: Minor
          Found in connectors/class-connector-widgets.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 handle_deactivated_widgets has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function handle_deactivated_widgets( $old, $new ) {
                  $new_deactivated_widget_ids = array_diff( $new['wp_inactive_widgets'], $old['wp_inactive_widgets'] );
          
                  foreach ( $new_deactivated_widget_ids as $widget_id ) {
                      $sidebar_id = '';
          Severity: Minor
          Found in connectors/class-connector-widgets.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 handle_widget_removal has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function handle_widget_removal( $old, $new ) {
                  $all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
                  $all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
                  // @todo In the customizer, moving widgets to other sidebars is problematic because each sidebar is registered as a separate setting; so we need to make sure that all $_POST['customized'] are applied?
                  // @todo The widget option is getting updated before the sidebars_widgets are updated, so we need to hook into the option update to try to cache any deletions for future lookup
          Severity: Minor
          Found in connectors/class-connector-widgets.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 handle_widget_removal has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function handle_widget_removal( $old, $new ) {
                  $all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
                  $all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
                  // @todo In the customizer, moving widgets to other sidebars is problematic because each sidebar is registered as a separate setting; so we need to make sure that all $_POST['customized'] are applied?
                  // @todo The widget option is getting updated before the sidebars_widgets are updated, so we need to hook into the option update to try to cache any deletions for future lookup
          Severity: Minor
          Found in connectors/class-connector-widgets.php - About 1 hr to fix

            Method handle_widget_addition has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function handle_widget_addition( $old, $new ) {
                    $all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
                    $all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
                    $added_widget_ids   = array_diff( $all_new_widget_ids, $all_old_widget_ids );
            
            
            Severity: Minor
            Found in connectors/class-connector-widgets.php - About 1 hr to fix

              Method handle_deactivated_widgets has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function handle_deactivated_widgets( $old, $new ) {
                      $new_deactivated_widget_ids = array_diff( $new['wp_inactive_widgets'], $old['wp_inactive_widgets'] );
              
                      foreach ( $new_deactivated_widget_ids as $widget_id ) {
                          $sidebar_id = '';
              Severity: Minor
              Found in connectors/class-connector-widgets.php - About 1 hr to fix

                Method handle_reactivated_widgets has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function handle_reactivated_widgets( $old, $new ) {
                        $new_reactivated_widget_ids = array_diff( $old['wp_inactive_widgets'], $new['wp_inactive_widgets'] );
                
                        foreach ( $new_reactivated_widget_ids as $widget_id ) {
                            $sidebar_id = '';
                Severity: Minor
                Found in connectors/class-connector-widgets.php - About 1 hr to fix

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

                      protected function handle_widget_reordering( $old, $new ) {
                          $all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
                  
                          foreach ( $all_sidebar_ids as $sidebar_id ) {
                              if ( $old[ $sidebar_id ] === $new[ $sidebar_id ] ) {
                  Severity: Minor
                  Found in connectors/class-connector-widgets.php - About 1 hr to fix

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

                        public function get_widget_instance( $widget_id ) {
                            $instance         = null;
                            $parsed_widget_id = $this->parse_widget_id( $widget_id );
                            $widget_obj       = $this->get_widget_object( $widget_id );
                    
                    
                    Severity: Minor
                    Found in connectors/class-connector-widgets.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 handle_widget_reordering has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function handle_widget_reordering( $old, $new ) {
                            $all_sidebar_ids = array_intersect( array_keys( $old ), array_keys( $new ) );
                    
                            foreach ( $all_sidebar_ids as $sidebar_id ) {
                                if ( $old[ $sidebar_id ] === $new[ $sidebar_id ] ) {
                    Severity: Minor
                    Found in connectors/class-connector-widgets.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

                        protected function handle_widget_removal( $old, $new ) {
                            $all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
                            $all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
                            // @todo In the customizer, moving widgets to other sidebars is problematic because each sidebar is registered as a separate setting; so we need to make sure that all $_POST['customized'] are applied?
                            // @todo The widget option is getting updated before the sidebars_widgets are updated, so we need to hook into the option update to try to cache any deletions for future lookup
                    Severity: Major
                    Found in connectors/class-connector-widgets.php and 1 other location - About 1 day to fix
                    connectors/class-connector-widgets.php on lines 359..407

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

                    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

                        protected function handle_widget_addition( $old, $new ) {
                            $all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $old ) ) );
                            $all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values( $new ) ) );
                            $added_widget_ids   = array_diff( $all_new_widget_ids, $all_old_widget_ids );
                    
                    
                    Severity: Major
                    Found in connectors/class-connector-widgets.php and 1 other location - About 1 day to fix
                    connectors/class-connector-widgets.php on lines 299..350

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

                    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

                                foreach ( $deletes as $delete ) {
                                    if ( $delete['name'] && $delete['title'] ) {
                                        /* translators: %1$s: a widget name, %2$s: a widget title (e.g. "Archives", "Browse") */
                                        $message = _x( '%1$s widget named "%2$s" deleted', '1: Name, 2: Title', 'stream' );
                                    } elseif ( $delete['name'] ) {
                    Severity: Major
                    Found in connectors/class-connector-widgets.php and 1 other location - About 5 hrs to fix
                    connectors/class-connector-widgets.php on lines 661..690

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

                    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

                                foreach ( $creates as $create ) {
                                    if ( $create['name'] && $create['title'] ) {
                                        /* translators: %1$s: a widget name, %2$s: a widget title (e.g. "Archives", "Browse") */
                                        $message = _x( '%1$s widget named "%2$s" created', '1: Name, 2: Title', 'stream' );
                                    } elseif ( $create['name'] ) {
                    Severity: Major
                    Found in connectors/class-connector-widgets.php and 1 other location - About 5 hrs to fix
                    connectors/class-connector-widgets.php on lines 695..724

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

                    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

                        public function get_action_labels() {
                            return array(
                                'added'       => esc_html__( 'Added', 'stream' ),
                                'removed'     => esc_html__( 'Removed', 'stream' ),
                                'moved'       => esc_html__( 'Moved', 'stream' ),
                    Severity: Major
                    Found in connectors/class-connector-widgets.php and 1 other location - About 3 hrs to fix
                    connectors/class-connector-media.php on lines 66..78

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

                    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

                                foreach ( $created_widget_numbers as $widget_number ) {
                                    $instance   = $new_value[ $widget_number ];
                                    $widget_id  = sprintf( $widget_id_format, $widget_number );
                                    $name       = $this->get_widget_name( $widget_id );
                                    $title      = ! empty( $instance['title'] ) ? $instance['title'] : null;
                    Severity: Major
                    Found in connectors/class-connector-widgets.php and 1 other location - About 1 hr to fix
                    connectors/class-connector-widgets.php on lines 592..600

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

                    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

                                foreach ( $deleted_widget_numbers as $widget_number ) {
                                    $instance   = $old_value[ $widget_number ];
                                    $widget_id  = sprintf( $widget_id_format, $widget_number );
                                    $name       = $this->get_widget_name( $widget_id );
                                    $title      = ! empty( $instance['title'] ) ? $instance['title'] : null;
                    Severity: Major
                    Found in connectors/class-connector-widgets.php and 1 other location - About 1 hr to fix
                    connectors/class-connector-widgets.php on lines 556..564

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

                    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