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
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
- Read upRead up
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
*
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
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))
- Read upRead up
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;
- Read upRead up
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)
- Read upRead up
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))
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;
Method _prepare_rules
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _prepare_rules($rules)
{
$new_rules = array();
$callbacks = array();
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)
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"' : '';
- Read upRead up
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();
- Read upRead up
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"' : '';
- Read upRead up
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;
- Read upRead up
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);
Avoid too many return
statements within this method. Open
return ' selected="selected"';
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return ' checked="checked"';
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)
{
- Read upRead up
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"' : '';
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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"' : '';
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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')
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76