bcit-ci/CodeIgniter

View on GitHub
system/libraries/Form_validation.php

Summary

Maintainability
F
1 wk
Test Coverage

File Form_validation.php has 748 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP
Severity: Major
Found in system/libraries/Form_validation.php - About 1 day to fix

    Function _execute has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
        {
            $allow_arrays = in_array('is_array', $rules, TRUE);
    
            // If the $_POST data is an array we will run a recursive call
    Severity: Minor
    Found in system/libraries/Form_validation.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

    CI_Form_validation has 53 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CI_Form_validation {
    
        /**
         * Reference to the CodeIgniter instance
         *
    Severity: Major
    Found in system/libraries/Form_validation.php - About 7 hrs to fix

      Method _execute has 151 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
          {
              $allow_arrays = in_array('is_array', $rules, TRUE);
      
              // If the $_POST data is an array we will run a recursive call
      Severity: Major
      Found in system/libraries/Form_validation.php - About 6 hrs to fix

        Function set_rules has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            public function set_rules($field, $label = null, $rules = null, $errors = array())
            {
                // No reason to set rules if we have no POST data
                // or a validation array has not been specified
                if ($this->CI->input->method() !== 'post' && empty($this->validation_data))
        Severity: Minor
        Found in system/libraries/Form_validation.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 run has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            public function run($config = NULL, &$data = NULL)
            {
                $validation_array = empty($this->validation_data)
                    ? $_POST
                    : $this->validation_data;
        Severity: Minor
        Found in system/libraries/Form_validation.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 _reset_data_array has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function _reset_data_array(&$data)
            {
                foreach ($this->_field_data as $field => $row)
                {
                    if ($row['postdata'] !== NULL)
        Severity: Minor
        Found in system/libraries/Form_validation.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 set_rules has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function set_rules($field, $label = null, $rules = null, $errors = array())
            {
                // No reason to set rules if we have no POST data
                // or a validation array has not been specified
                if ($this->CI->input->method() !== 'post' && empty($this->validation_data))
        Severity: Major
        Found in system/libraries/Form_validation.php - About 2 hrs to fix

          Method run has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function run($config = NULL, &$data = NULL)
              {
                  $validation_array = empty($this->validation_data)
                      ? $_POST
                      : $this->validation_data;
          Severity: Major
          Found in system/libraries/Form_validation.php - About 2 hrs to fix

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

                protected function _prepare_rules($rules)
                {
                    $new_rules = array();
                    $callbacks = array();
            
            
            Severity: Minor
            Found in system/libraries/Form_validation.php - About 1 hr to fix

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

                  protected function _reset_data_array(&$data)
                  {
                      foreach ($this->_field_data as $field => $row)
                      {
                          if ($row['postdata'] !== NULL)
              Severity: Minor
              Found in system/libraries/Form_validation.php - About 1 hr to fix

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

                    public function set_select($field = '', $value = '', $default = FALSE)
                    {
                        if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
                        {
                            return ($default === TRUE && count($this->_field_data) === 0) ? ' selected="selected"' : '';
                Severity: Minor
                Found in system/libraries/Form_validation.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 _prepare_rules has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function _prepare_rules($rules)
                    {
                        $new_rules = array();
                        $callbacks = array();
                
                
                Severity: Minor
                Found in system/libraries/Form_validation.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 set_radio has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function set_radio($field = '', $value = '', $default = FALSE)
                    {
                        if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
                        {
                            return ($default === TRUE && count($this->_field_data) === 0) ? ' checked="checked"' : '';
                Severity: Minor
                Found in system/libraries/Form_validation.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 valid_url has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function valid_url($str)
                    {
                        if (empty($str))
                        {
                            return FALSE;
                Severity: Minor
                Found in system/libraries/Form_validation.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

                Avoid too many return statements within this method.
                Open

                        return (filter_var('http://'.$str, FILTER_VALIDATE_URL) !== FALSE);
                Severity: Major
                Found in system/libraries/Form_validation.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return ' selected="selected"';
                  Severity: Major
                  Found in system/libraries/Form_validation.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return TRUE;
                    Severity: Major
                    Found in system/libraries/Form_validation.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return ' checked="checked"';
                      Severity: Major
                      Found in system/libraries/Form_validation.php - About 30 mins to fix

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

                            public function error_string($prefix = '', $suffix = '')
                            {
                                // No errors, validation passes!
                                if (count($this->_error_array) === 0)
                                {
                        Severity: Minor
                        Found in system/libraries/Form_validation.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 set_select($field = '', $value = '', $default = FALSE)
                            {
                                if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
                                {
                                    return ($default === TRUE && count($this->_field_data) === 0) ? ' selected="selected"' : '';
                        Severity: Major
                        Found in system/libraries/Form_validation.php and 1 other location - About 4 hrs to fix
                        system/libraries/Form_validation.php on lines 1000..1028

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

                        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 set_radio($field = '', $value = '', $default = FALSE)
                            {
                                if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
                                {
                                    return ($default === TRUE && count($this->_field_data) === 0) ? ' checked="checked"' : '';
                        Severity: Major
                        Found in system/libraries/Form_validation.php and 1 other location - About 4 hrs to fix
                        system/libraries/Form_validation.php on lines 957..985

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

                        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 valid_email($str)
                            {
                                if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
                                {
                                    $domain = defined('INTL_IDNA_VARIANT_UTS46')
                        Severity: Major
                        Found in system/libraries/Form_validation.php and 1 other location - About 2 hrs to fix
                        system/libraries/Email.php on lines 1014..1029

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

                        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