awsmug/torro-forms

View on GitHub
src/db-objects/submissions/submission.php

Summary

Maintainability
F
3 days
Test Coverage

File submission.php has 394 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Submission class
 *
 * @package TorroForms
Severity: Minor
Found in src/db-objects/submissions/submission.php - About 5 hrs to fix

    Function sync_upstream has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public function sync_upstream() {
            $result = parent::sync_upstream();
    
            if ( is_wp_error( $result ) ) {
                return $result;
    Severity: Minor
    Found in src/db-objects/submissions/submission.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 __set has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        public function __set( $property, $value ) {
            if ( 'values' === $property ) {
                $this->set_submission_values_data( $value );
                return;
            }
    Severity: Minor
    Found in src/db-objects/submissions/submission.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

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

    class Submission extends Model {
        use Sitewide_Model_Trait;
    
        /**
         * Submission ID.
    Severity: Minor
    Found in src/db-objects/submissions/submission.php - About 2 hrs to fix

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

          public function sync_upstream() {
              $result = parent::sync_upstream();
      
              if ( is_wp_error( $result ) ) {
                  return $result;
      Severity: Minor
      Found in src/db-objects/submissions/submission.php - About 1 hr to fix

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

            public function __set( $property, $value ) {
                if ( 'values' === $property ) {
                    $this->set_submission_values_data( $value );
                    return;
                }
        Severity: Minor
        Found in src/db-objects/submissions/submission.php - About 1 hr to fix

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

              public function reset_errors( $element_id = null ) {
                  if ( ! array_key_exists( 'errors', $this->pending_meta ) ) {
                      if ( ! $this->primary_property_value() ) {
                          return false;
                      }
          Severity: Minor
          Found in src/db-objects/submissions/submission.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 remove_error has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function remove_error( $element_id, $code ) {
                  if ( ! array_key_exists( 'errors', $this->pending_meta ) ) {
                      if ( $this->primary_property_value() ) {
                          $this->pending_meta['errors'] = $this->manager->get_meta( $this->primary_property_value(), 'errors', true );
                      } else {
          Severity: Minor
          Found in src/db-objects/submissions/submission.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 get_errors has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function get_errors( $element_id = null ) {
                  if ( ! array_key_exists( 'errors', $this->pending_meta ) ) {
                      if ( ! $this->primary_property_value() ) {
                          return array();
                      }
          Severity: Minor
          Found in src/db-objects/submissions/submission.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 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function __get( $property ) {
                  if ( 'values' === $property ) {
                      if ( is_array( $this->values ) ) {
                          return $this->values;
                      }
          Severity: Minor
          Found in src/db-objects/submissions/submission.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 add_error has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function add_error( $element_id, $code, $message ) {
                  if ( ! array_key_exists( 'errors', $this->pending_meta ) ) {
                      if ( $this->primary_property_value() ) {
                          $this->pending_meta['errors'] = $this->manager->get_meta( $this->primary_property_value(), 'errors', true );
                      } else {
          Severity: Minor
          Found in src/db-objects/submissions/submission.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

          Avoid too many return statements within this method.
          Open

                  return parent::__get( $property );
          Severity: Major
          Found in src/db-objects/submissions/submission.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return true;
            Severity: Major
            Found in src/db-objects/submissions/submission.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $errors;
              Severity: Major
              Found in src/db-objects/submissions/submission.php - About 30 mins to fix

                Function get_current_container has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function get_current_container() {
                        $container_id = (int) $this->__get( 'current_container_id' );
                
                        if ( ! empty( $container_id ) ) {
                            $container = $this->manager->get_parent_manager( 'forms' )->get_child_manager( 'containers' )->get( $container_id );
                Severity: Minor
                Found in src/db-objects/submissions/submission.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

                    public function get_next_container() {
                        $container = $this->get_current_container();
                        if ( ! $container ) {
                            return null;
                        }
                Severity: Major
                Found in src/db-objects/submissions/submission.php and 1 other location - About 2 hrs to fix
                src/db-objects/submissions/submission.php on lines 494..522

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

                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_previous_container() {
                        $container = $this->get_current_container();
                        if ( ! $container ) {
                            return null;
                        }
                Severity: Major
                Found in src/db-objects/submissions/submission.php and 1 other location - About 2 hrs to fix
                src/db-objects/submissions/submission.php on lines 457..485

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

                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 4 locations. Consider refactoring.
                Open

                    public function get_submission_values( $args = array() ) {
                        if ( empty( $this->id ) ) {
                            return $this->manager->get_child_manager( 'submission_values' )->get_collection( array(), 0, 'objects' );
                        }
                
                
                Severity: Major
                Found in src/db-objects/submissions/submission.php and 3 other locations - About 40 mins to fix
                src/db-objects/containers/container.php on lines 86..100
                src/db-objects/elements/element.php on lines 101..115
                src/db-objects/elements/element.php on lines 125..139

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

                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