awsmug/torro-forms

View on GitHub
src/db-objects/elements/element-types/element-type.php

Summary

Maintainability
F
3 days
Test Coverage

Function get_values has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring.
Open

    public function get_values( $element, $submission = null ) {
        $values = array();
        if ( $submission ) {
            $all_values = $submission->get_element_values_data();
            if ( isset( $all_values[ $element->id ] ) ) {
Severity: Minor
Found in src/db-objects/elements/element-types/element-type.php - About 1 day 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

File element-type.php has 362 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Element type base class
 *
 * @package TorroForms
Severity: Minor
Found in src/db-objects/elements/element-types/element-type.php - About 4 hrs to fix

    Element_Type has 28 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class Element_Type {
    
        /**
         * Error code to use when the error says the field is required.
         *
    Severity: Minor
    Found in src/db-objects/elements/element-types/element-type.php - About 3 hrs to fix

      Function sanitize_settings_fields has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          final protected function sanitize_settings_fields() {
              $defaults = array(
                  'section'     => '',
                  'type'        => 'text',
                  'label'       => '',
      Severity: Minor
      Found in src/db-objects/elements/element-types/element-type.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 get_values has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_values( $element, $submission = null ) {
              $values = array();
              if ( $submission ) {
                  $all_values = $submission->get_element_values_data();
                  if ( isset( $all_values[ $element->id ] ) ) {
      Severity: Minor
      Found in src/db-objects/elements/element-types/element-type.php - About 1 hr to fix

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

            public function filter_json( $data, $element, $submission = null ) {
                $data['template_suffix'] = $this->slug;
        
                $settings = $this->get_settings( $element );
                $values   = $this->get_values( $element, $submission );
        Severity: Minor
        Found in src/db-objects/elements/element-types/element-type.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 filter_json has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function filter_json( $data, $element, $submission = null ) {
                $data['template_suffix'] = $this->slug;
        
                $settings = $this->get_settings( $element );
                $values   = $this->get_values( $element, $submission );
        Severity: Minor
        Found in src/db-objects/elements/element-types/element-type.php - About 1 hr to fix

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

              final protected function sanitize_settings_fields() {
                  $defaults = array(
                      'section'     => '',
                      'type'        => 'text',
                      'label'       => '',
          Severity: Minor
          Found in src/db-objects/elements/element-types/element-type.php - About 1 hr to fix

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

                protected function escape_single_value_for_export( $value, $export_format ) {
                    switch ( $export_format ) {
                        case 'xls':
                        case 'csv':
                            if ( is_array( $value ) && is_string( $value[ key( $value ) ] ) ) {
            Severity: Minor
            Found in src/db-objects/elements/element-types/element-type.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

            Avoid deeply nested control flow statements.
            Open

                                    if ( is_array( $get_params ) ) {
                                        foreach ( $get_params as $field => $value ) {
                                            if ( empty( $values[ $field ] ) ) {
                                                if ( ! empty( $choices[ $field ] ) ) {
                                                    if ( isset( $choices[ $field ][ $value ] ) ) {
            Severity: Major
            Found in src/db-objects/elements/element-types/element-type.php - About 45 mins to fix

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

                  public function get_edit_submission_fields_args( $element ) {
                      $settings = $this->get_settings( $element );
              
                      $slug = $this->get_edit_submission_field_slug( $element->id );
                      $args = array(
              Severity: Minor
              Found in src/db-objects/elements/element-types/element-type.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