bcit-ci/CodeIgniter

View on GitHub
system/helpers/date_helper.php

Summary

Maintainability
F
4 days
Test Coverage

File date_helper.php has 397 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP
Severity: Minor
Found in system/helpers/date_helper.php - About 5 hrs to fix

    Function timespan has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        function timespan($seconds = 1, $time = '', $units = 7)
        {
            $CI =& get_instance();
            $CI->lang->load('date');
    
    
    Severity: Minor
    Found in system/helpers/date_helper.php - About 4 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 timespan has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function timespan($seconds = 1, $time = '', $units = 7)
        {
            $CI =& get_instance();
            $CI->lang->load('date');
    
    
    Severity: Major
    Found in system/helpers/date_helper.php - About 2 hrs to fix

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

          function nice_date($bad_date = '', $format = FALSE)
          {
              if (empty($bad_date))
              {
                  return 'Unknown';
      Severity: Minor
      Found in system/helpers/date_helper.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 timezones has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function timezones($tz = '')
          {
              // Note: Don't change the order of these even though
              // some items appear to be in the wrong order
      
      
      Severity: Minor
      Found in system/helpers/date_helper.php - About 1 hr to fix

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

            function date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d')
            {
                if ($unix_start == '' OR $mixed == '' OR $format == '')
                {
                    return FALSE;
        Severity: Minor
        Found in system/helpers/date_helper.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 days_in_month has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            function days_in_month($month = 0, $year = '')
            {
                if ($month < 1 OR $month > 12)
                {
                    return 0;
        Severity: Minor
        Found in system/helpers/date_helper.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 date_range has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d')
            {
                if ($unix_start == '' OR $mixed == '' OR $format == '')
                {
                    return FALSE;
        Severity: Minor
        Found in system/helpers/date_helper.php - About 1 hr to fix

          Method nice_date has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function nice_date($bad_date = '', $format = FALSE)
              {
                  if (empty($bad_date))
                  {
                      return 'Unknown';
          Severity: Minor
          Found in system/helpers/date_helper.php - About 1 hr to fix

            Function human_to_unix has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                function human_to_unix($datestr = '')
                {
                    if ($datestr === '')
                    {
                        return FALSE;
            Severity: Minor
            Found in system/helpers/date_helper.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 unix_to_human has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us')
                {
                    $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' ';
            
                    if ($fmt === 'us')
            Severity: Minor
            Found in system/helpers/date_helper.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

            Avoid too many return statements within this method.
            Open

                        return 'Invalid Date';
            Severity: Major
            Found in system/helpers/date_helper.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $days_in_month[$month - 1];
              Severity: Major
              Found in system/helpers/date_helper.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return date($format, strtotime($bad_date));
                Severity: Major
                Found in system/helpers/date_helper.php - About 30 mins to fix

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

                          if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0))
                          {
                              if ($days > 0)
                              {
                                  $str[] = $days.' '.$CI->lang->line($days > 1 ? 'date_days' : 'date_day');
                  Severity: Major
                  Found in system/helpers/date_helper.php and 2 other locations - About 1 hr to fix
                  system/helpers/date_helper.php on lines 172..180
                  system/helpers/date_helper.php on lines 208..216

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

                  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 3 locations. Consider refactoring.
                  Open

                          if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0))
                          {
                              if ($weeks > 0)
                              {
                                  $str[] = $weeks.' '.$CI->lang->line($weeks > 1 ? 'date_weeks' : 'date_week');
                  Severity: Major
                  Found in system/helpers/date_helper.php and 2 other locations - About 1 hr to fix
                  system/helpers/date_helper.php on lines 184..192
                  system/helpers/date_helper.php on lines 208..216

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

                  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 3 locations. Consider refactoring.
                  Open

                          if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0))
                          {
                              if ($minutes > 0)
                              {
                                  $str[] = $minutes.' '.$CI->lang->line($minutes > 1 ? 'date_minutes' : 'date_minute');
                  Severity: Major
                  Found in system/helpers/date_helper.php and 2 other locations - About 1 hr to fix
                  system/helpers/date_helper.php on lines 172..180
                  system/helpers/date_helper.php on lines 184..192

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

                  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

                          if (count($str) < $units && ($years > 0 OR $months > 0))
                          {
                              if ($months > 0)
                              {
                                  $str[] = $months.' '.$CI->lang->line($months > 1 ? 'date_months' : 'date_month');
                  Severity: Minor
                  Found in system/helpers/date_helper.php and 1 other location - About 1 hr to fix
                  system/helpers/date_helper.php on lines 196..204

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

                  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

                          if (count($str) < $units && ($days > 0 OR $hours > 0))
                          {
                              if ($hours > 0)
                              {
                                  $str[] = $hours.' '.$CI->lang->line($hours > 1 ? 'date_hours' : 'date_hour');
                  Severity: Minor
                  Found in system/helpers/date_helper.php and 1 other location - About 1 hr to fix
                  system/helpers/date_helper.php on lines 160..168

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

                  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