includes/lib/Carbon.php

Summary

Maintainability
F
6 days
Test Coverage

Carbon has 142 functions (exceeds 20 allowed). Consider refactoring.
Open

class Carbon extends DateTime
{
    /**
     * The day constants
     */
Severity: Major
Found in includes/lib/Carbon.php - About 2 days to fix

    File Carbon.php has 857 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /*
     * This file is part of the Carbon package.
     *
    Severity: Major
    Found in includes/lib/Carbon.php - About 2 days to fix

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

          public function __get($name)
          {
              switch ($name) {
                  case 'year':
                  case 'month':
      Severity: Major
      Found in includes/lib/Carbon.php - About 2 hrs to fix

        Method diffForHumans has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function diffForHumans(Carbon $other = null)
            {
                $isNow = $other === null;
        
                if ($isNow) {
        Severity: Minor
        Found in includes/lib/Carbon.php - About 1 hr to fix

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

              public function __construct($time = null, $tz = null)
              {
                  // If the class has a test now set and we are trying to create a now()
                  // instance then override as required
                  if (static::hasTestNow() && (empty($time) || $time === 'now' || static::hasRelativeKeywords($time))) {
          Severity: Minor
          Found in includes/lib/Carbon.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 __set has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function __set($name, $value)
              {
                  switch ($name) {
                      case 'year':
                          parent::setDate($value, $this->month, $this->day);
          Severity: Minor
          Found in includes/lib/Carbon.php - About 1 hr to fix

            Function diffForHumans has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                public function diffForHumans(Carbon $other = null)
                {
                    $isNow = $other === null;
            
                    if ($isNow) {
            Severity: Minor
            Found in includes/lib/Carbon.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 __set has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                public function __set($name, $value)
                {
                    switch ($name) {
                        case 'year':
                            parent::setDate($value, $this->month, $this->day);
            Severity: Minor
            Found in includes/lib/Carbon.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

            Method create has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null)
            Severity: Major
            Found in includes/lib/Carbon.php - About 50 mins to fix

              Method setDateTime has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public function setDateTime($year, $month, $day, $hour, $minute, $second = 0)
              Severity: Minor
              Found in includes/lib/Carbon.php - About 45 mins to fix

                Avoid too many return statements within this method.
                Open

                                return $this->offset == $this->copy()->setTimezone(date_default_timezone_get())->offset;
                Severity: Major
                Found in includes/lib/Carbon.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return $this->offset == 0;
                  Severity: Major
                  Found in includes/lib/Carbon.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return $this->getOffset() / self::SECONDS_PER_MINUTE / self::MINUTES_PER_HOUR;
                    Severity: Major
                    Found in includes/lib/Carbon.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return $this->getOffset();
                      Severity: Major
                      Found in includes/lib/Carbon.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return $this->getTimezone()->getName();
                        Severity: Major
                        Found in includes/lib/Carbon.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return $this->format('I') == '1';
                          Severity: Major
                          Found in includes/lib/Carbon.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return $this->getTimezone();
                            Severity: Major
                            Found in includes/lib/Carbon.php - About 30 mins to fix

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

                                  public static function hasRelativeKeywords($time)
                                  {
                                      // skip common format with a '-' in it
                                      if (preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) {
                                          foreach (static::$relativeKeywords as $keyword) {
                              Severity: Minor
                              Found in includes/lib/Carbon.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

                              There are no issues that match your filters.

                              Category
                              Status