classes/yf_validate.class.php

Summary

Maintainability
F
1 wk
Test Coverage

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.
 */
Severity: Major
Found in classes/yf_validate.class.php - About 2 days to fix

    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) */
    Severity: Major
    Found in classes/yf_validate.class.php - About 1 day to fix

      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);
      Severity: Minor
      Found in classes/yf_validate.class.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

      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])) {
      Severity: Minor
      Found in classes/yf_validate.class.php - About 6 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 _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);
      Severity: Major
      Found in classes/yf_validate.class.php - About 4 hrs to fix

        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])) {
        Severity: Major
        Found in classes/yf_validate.class.php - About 2 hrs to fix

          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 = '|';
          Severity: Minor
          Found in classes/yf_validate.class.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 _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);
          Severity: Minor
          Found in classes/yf_validate.class.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 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
          Severity: Minor
          Found in classes/yf_validate.class.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 _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);
          Severity: Minor
          Found in classes/yf_validate.class.php - About 1 hr to fix

            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) {
            Severity: Minor
            Found in classes/yf_validate.class.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

            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) {
            Severity: Major
            Found in classes/yf_validate.class.php - About 40 mins to fix

              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;
              
              
              Severity: Minor
              Found in classes/yf_validate.class.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 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);
              Severity: Minor
              Found in classes/yf_validate.class.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 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;
                      }
              Severity: Minor
              Found in classes/yf_validate.class.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

              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;
                      }
              Severity: Minor
              Found in classes/yf_validate.class.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

              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) {
              Severity: Minor
              Found in classes/yf_validate.class.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

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

                  public function valid_emails($in)
                  {
                      if ( ! $in) {
                          return false;
                      }
              Severity: Minor
              Found in classes/yf_validate.class.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

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

                  public function exists($in, $params = [])
                  {
                      if ( ! $in) {
                          return false;
                      }
              Severity: Minor
              Found in classes/yf_validate.class.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

              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
              Severity: Minor
              Found in classes/yf_validate.class.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 exists($in, $params = [])
                  {
                      if ( ! $in) {
                          return false;
                      }
              Severity: Major
              Found in classes/yf_validate.class.php and 1 other location - About 4 hrs to fix
              classes/yf_validate.class.php on lines 603..623

              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

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function is_unique($in, $params = [])
                  {
                      if ( ! $in) {
                          return true;
                      }
              Severity: Major
              Found in classes/yf_validate.class.php and 1 other location - About 4 hrs to fix
              classes/yf_validate.class.php on lines 661..681

              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

              Further Reading

              There are no issues that match your filters.

              Category
              Status