awsmug/torro-forms

View on GitHub
src/db-objects/forms/form-edit-page-handler.php

Summary

Maintainability
F
1 wk
Test Coverage

File form-edit-page-handler.php has 751 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Form edit page handler class
 *
 * @package TorroForms
Severity: Major
Found in src/db-objects/forms/form-edit-page-handler.php - About 1 day to fix

    Method print_templates has 134 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function print_templates() {
            ?>
            <script type="text/html" id="tmpl-torro-failure">
                <div class="torro-notice notice-error">
                    <p>
    Severity: Major
    Found in src/db-objects/forms/form-edit-page-handler.php - About 5 hrs to fix

      Form_Edit_Page_Handler has 32 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Form_Edit_Page_Handler {
      
          /**
           * Form manager instance.
           *
      Severity: Minor
      Found in src/db-objects/forms/form-edit-page-handler.php - About 4 hrs to fix

        Function handle_save_request has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

            private function handle_save_request( $form ) {
                $this->current_form = $form;
        
                $mappings = array(
                    'forms'            => array(
        Severity: Minor
        Found in src/db-objects/forms/form-edit-page-handler.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

        Method handle_save_request has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function handle_save_request( $form ) {
                $this->current_form = $form;
        
                $mappings = array(
                    'forms'            => array(
        Severity: Major
        Found in src/db-objects/forms/form-edit-page-handler.php - About 2 hrs to fix

          Function save_elements has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              private function save_elements( $elements, $mappings, $errors ) {
                  $element_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' );
          
                  foreach ( $elements as $id => $data ) {
                      if ( empty( $data['container_id'] ) || ! isset( $mappings['containers'][ $data['container_id'] ] ) ) {
          Severity: Minor
          Found in src/db-objects/forms/form-edit-page-handler.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

          Function save_element_settings has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              private function save_element_settings( $element_settings, $mappings, $errors ) {
                  $element_setting_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_settings' );
          
                  foreach ( $element_settings as $id => $data ) {
                      if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
          Severity: Minor
          Found in src/db-objects/forms/form-edit-page-handler.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

          Function save_element_choices has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              private function save_element_choices( $element_choices, $mappings, $errors ) {
                  $element_choice_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_choices' );
          
                  foreach ( $element_choices as $id => $data ) {
                      if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
          Severity: Minor
          Found in src/db-objects/forms/form-edit-page-handler.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 add_meta_boxes has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function add_meta_boxes( $form ) {
                  $this->current_form = $form;
          
                  if ( ! did_action( "{$this->form_manager->get_prefix()}add_form_meta_content" ) ) {
                      /**
          Severity: Minor
          Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

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

                private function save_containers( $containers, $mappings, $errors ) {
                    $container_manager = $this->form_manager->get_child_manager( 'containers' );
            
                    foreach ( $containers as $id => $data ) {
                        $data['form_id'] = key( $mappings['forms'] );
            Severity: Minor
            Found in src/db-objects/forms/form-edit-page-handler.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 save_elements has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function save_elements( $elements, $mappings, $errors ) {
                    $element_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' );
            
                    foreach ( $elements as $id => $data ) {
                        if ( empty( $data['container_id'] ) || ! isset( $mappings['containers'][ $data['container_id'] ] ) ) {
            Severity: Minor
            Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

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

                  private function save_element_settings( $element_settings, $mappings, $errors ) {
                      $element_setting_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_settings' );
              
                      foreach ( $element_settings as $id => $data ) {
                          if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
              Severity: Minor
              Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

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

                    private function save_element_choices( $element_choices, $mappings, $errors ) {
                        $element_choice_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_choices' );
                
                        foreach ( $element_choices as $id => $data ) {
                            if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
                Severity: Minor
                Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

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

                      public function action_duplicate_form() {
                          $nonce   = filter_input( INPUT_GET, '_wpnonce' );
                          $form_id = filter_input( INPUT_GET, 'form_id', FILTER_VALIDATE_INT );
                  
                          if ( empty( $form_id ) ) {
                  Severity: Minor
                  Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

                    Method add_meta_box has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function add_meta_box( $id, $args ) {
                            $prefix = $this->form_manager->get_prefix();
                    
                            if ( 0 !== strpos( $id, $prefix ) ) {
                                $id = $prefix . $id;
                    Severity: Minor
                    Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

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

                          private function save_containers( $containers, $mappings, $errors ) {
                              $container_manager = $this->form_manager->get_child_manager( 'containers' );
                      
                              foreach ( $containers as $id => $data ) {
                                  $data['form_id'] = key( $mappings['forms'] );
                      Severity: Minor
                      Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

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

                            public function maybe_show_duplicate_form_feedback() {
                                $meta_key = $this->form_manager->get_prefix() . 'duplicate_feedback';
                        
                                $form_id = filter_input( INPUT_GET, $meta_key, FILTER_VALIDATE_INT );
                                if ( empty( $form_id ) ) {
                        Severity: Minor
                        Found in src/db-objects/forms/form-edit-page-handler.php - About 1 hr to fix

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

                              public function maybe_add_duplicate_button( $output, $post_id, $new_title, $new_slug, $post ) {
                          Severity: Minor
                          Found in src/db-objects/forms/form-edit-page-handler.php - About 35 mins to fix

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

                                public function maybe_add_submissions_button( $output, $post_id, $new_title, $new_slug, $post ) {
                            Severity: Minor
                            Found in src/db-objects/forms/form-edit-page-handler.php - About 35 mins to fix

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

                                  private function add_meta_boxes( $form ) {
                                      $this->current_form = $form;
                              
                                      if ( ! did_action( "{$this->form_manager->get_prefix()}add_form_meta_content" ) ) {
                                          /**
                              Severity: Minor
                              Found in src/db-objects/forms/form-edit-page-handler.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 action_duplicate_form has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function action_duplicate_form() {
                                      $nonce   = filter_input( INPUT_GET, '_wpnonce' );
                                      $form_id = filter_input( INPUT_GET, 'form_id', FILTER_VALIDATE_INT );
                              
                                      if ( empty( $form_id ) ) {
                              Severity: Minor
                              Found in src/db-objects/forms/form-edit-page-handler.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 maybe_enqueue_assets has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function maybe_enqueue_assets( $hook_suffix ) {
                                      if ( 'post-new.php' !== $hook_suffix && 'post.php' !== $hook_suffix ) {
                                          return;
                                      }
                              
                              
                              Severity: Minor
                              Found in src/db-objects/forms/form-edit-page-handler.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

                                  private function save_element_choices( $element_choices, $mappings, $errors ) {
                                      $element_choice_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_choices' );
                              
                                      foreach ( $element_choices as $id => $data ) {
                                          if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
                              Severity: Major
                              Found in src/db-objects/forms/form-edit-page-handler.php and 1 other location - About 1 day to fix
                              src/db-objects/forms/form-edit-page-handler.php on lines 1180..1219

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

                              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

                                  private function save_element_settings( $element_settings, $mappings, $errors ) {
                                      $element_setting_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_settings' );
                              
                                      foreach ( $element_settings as $id => $data ) {
                                          if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
                              Severity: Major
                              Found in src/db-objects/forms/form-edit-page-handler.php and 1 other location - About 1 day to fix
                              src/db-objects/forms/form-edit-page-handler.php on lines 1129..1168

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

                              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 add_tab( $id, $args ) {
                                      if ( ! empty( $args['meta_box'] ) ) {
                                          $prefix = $this->form_manager->get_prefix();
                              
                                          if ( 0 !== strpos( $args['meta_box'], $prefix ) ) {
                              Severity: Major
                              Found in src/db-objects/forms/form-edit-page-handler.php and 1 other location - About 1 hr to fix
                              src/db-objects/forms/form-settings-page.php on lines 118..135

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

                              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