File yf_validate.class.php
has 911 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Validation common methods, part of this was inspired by codeigniter 2.1 form_validate.
*/
yf_validate
has 89 functions (exceeds 20 allowed). Consider refactoring. Open
class yf_validate
{
/** @var int Minimal nick length */
public $MIN_NICK_LENGTH = 2;
/** @var array Allowed nick symbols (display for user) */
Function _validate_rules_cleanup
has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring. Open
public function _validate_rules_cleanup($validate_rules = [])
{
// Trim names with spaces
foreach ((array) $validate_rules as $name => $raw) {
$trimmed = trim($name);
- 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 _do_check_data_is_valid
has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring. Open
public function _do_check_data_is_valid($rules = [], &$data)
{
$validate_ok = true;
$_all = '__all__';
if (isset($rules[$_all])) {
- 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 _validate_rules_cleanup
has 103 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _validate_rules_cleanup($validate_rules = [])
{
// Trim names with spaces
foreach ((array) $validate_rules as $name => $raw) {
$trimmed = trim($name);
Method _do_check_data_is_valid
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _do_check_data_is_valid($rules = [], &$data)
{
$validate_ok = true;
$_all = '__all__';
if (isset($rules[$_all])) {
Function _validate_rules_array_from_raw
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function _validate_rules_array_from_raw($raw = '')
{
$rules = [];
// esxape '|' to '\|'
$delimeter = '|';
- 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 _check_location
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function _check_location($cur_country = '', $cur_region = '', $cur_city = '')
{
// TODO: rewrite me
if (FEATURED_COUNTRY_SELECT && ! empty($_POST['country']) && substr($_POST['country'], 0, 2) == 'f_') {
$_POST['country'] = substr($_POST['country'], 2);
- 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 required_any
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function required_any($in, $params = [], $fields = [])
{
$param = trim(is_array($params) ? $params['param'] : $params);
$wildcard = false;
// Example: duration_day,duration_week,duration_month
- 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 _check_location
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _check_location($cur_country = '', $cur_region = '', $cur_city = '')
{
// TODO: rewrite me
if (FEATURED_COUNTRY_SELECT && ! empty($_POST['country']) && substr($_POST['country'], 0, 2) == 'f_') {
$_POST['country'] = substr($_POST['country'], 2);
Function _check_user_nick
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function _check_user_nick($CUR_VALUE = '', $force_value_to_check = null, $name_in_form = 'nick')
{
// TODO: rewrite me
$TEXT_TO_CHECK = $_POST[$name_in_form];
if ($force_value_to_check !== 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
Consider simplifying this complex logical expression. Open
if ($_POST['year_birth'] >= 1915 && $_POST['year_birth'] <= (date('Y') - 17)
&& $_POST['month_birth'] >= 1 && $_POST['month_birth'] <= 12
&& $_POST['day_birth'] >= 1 && $_POST['day_birth'] <= 31
) {
if ($_POST['month_birth'] < 10) {
Function _check_birth_date
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function _check_birth_date($CUR_VALUE = '')
{
// TODO: rewrite me
$_POST['birth_date'] = $CUR_VALUE;
- 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 phone_cleanup
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function phone_cleanup($in, $params = [], $fields = [], &$error = '')
{
$error = false;
$country_prefix = $params['param'] ?: '38';
$p_len = strlen($country_prefix);
- 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 is_unique_without
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function is_unique_without($in, $params = [])
{
if ( ! $in) {
return true;
}
- 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 is_unique
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function is_unique($in, $params = [])
{
if ( ! $in) {
return true;
}
- 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 required
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function required($in)
{
if (is_array($in)) {
$func = __FUNCTION__;
foreach ($in as $v) {
- 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_emails
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function valid_emails($in)
{
if ( ! $in) {
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
Function exists
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function exists($in, $params = [])
{
if ( ! $in) {
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
Function _check_profile_url
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function _check_profile_url($CUR_VALUE = '', $force_value_to_check = null, $name_in_form = 'profile_url')
{
// TODO: rewrite me
$TEXT_TO_CHECK = $_POST[$name_in_form];
// Override value to check
- 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 exists($in, $params = [])
{
if ( ! $in) {
return false;
}
- 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 175.
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 is_unique($in, $params = [])
{
if ( ! $in) {
return true;
}
- 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 175.
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