qcubed/framework

View on GitHub
includes/framework/QDateTimeSpan.class.php

Summary

Maintainability
B
5 hrs
Test Coverage

The class QDateTimeSpan has an overall complexity of 55 which is very high. The configured complexity threshold is 50.
Open

    class QDateTimeSpan extends QBaseClass{
        /** @var int Seconds variable which will be used to calculate the timespan */
        protected $intSeconds;

        /* From: http://tycho.usno.navy.mil/leapsec.html:

The class QDateTimeSpan has 12 public methods. Consider refactoring QDateTimeSpan to keep number of public methods under 10.
Open

    class QDateTimeSpan extends QBaseClass{
        /** @var int Seconds variable which will be used to calculate the timespan */
        protected $intSeconds;

        /* From: http://tycho.usno.navy.mil/leapsec.html:

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

QDateTimeSpan has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

    class QDateTimeSpan extends QBaseClass{
        /** @var int Seconds variable which will be used to calculate the timespan */
        protected $intSeconds;

        /* From: http://tycho.usno.navy.mil/leapsec.html:
Severity: Minor
Found in includes/framework/QDateTimeSpan.class.php - About 2 hrs to fix

    Method SimpleDisplay has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            public function SimpleDisplay(){
                $arrTimearray = $this->GetTimearray();
                $strToReturn = null;
    
                if($arrTimearray['Years'] != 0) {
    Severity: Minor
    Found in includes/framework/QDateTimeSpan.class.php - About 1 hr to fix

      Avoid too many return statements within this method.
      Open

                      case 'Minutes': return $this->GetMinutes();
      Severity: Major
      Found in includes/framework/QDateTimeSpan.class.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                                return parent::__get($strName);
        Severity: Major
        Found in includes/framework/QDateTimeSpan.class.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          case 'Timearray' : return ($this->GetTimearray());
          Severity: Major
          Found in includes/framework/QDateTimeSpan.class.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            case 'Seconds': return $this->intSeconds;
            Severity: Major
            Found in includes/framework/QDateTimeSpan.class.php - About 30 mins to fix

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

                      public function SimpleDisplay(){
                          $arrTimearray = $this->GetTimearray();
                          $strToReturn = null;
              
                          if($arrTimearray['Years'] != 0) {
              Severity: Minor
              Found in includes/framework/QDateTimeSpan.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

              The method SimpleDisplay() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
              Open

                      public function SimpleDisplay(){
                          $arrTimearray = $this->GetTimearray();
                          $strToReturn = null;
              
                          if($arrTimearray['Years'] != 0) {

              CyclomaticComplexity

              Since: 0.1

              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

              Example

              // Cyclomatic Complexity = 11
              class Foo {
              1   public function example() {
              2       if ($a == $b) {
              3           if ($a1 == $b1) {
                              fiddle();
              4           } elseif ($a2 == $b2) {
                              fiddle();
                          } else {
                              fiddle();
                          }
              5       } elseif ($c == $d) {
              6           while ($c == $d) {
                              fiddle();
                          }
              7        } elseif ($e == $f) {
              8           for ($n = 0; $n < $h; $n++) {
                              fiddle();
                          }
                      } else {
                          switch ($z) {
              9               case 1:
                                  fiddle();
                                  break;
              10              case 2:
                                  fiddle();
                                  break;
              11              case 3:
                                  fiddle();
                                  break;
                              default:
                                  fiddle();
                                  break;
                          }
                      }
                  }
              }

              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

              Missing class import via use statement (line '85', column '23').
              Open

                          $dtsDateSpan = new QDateTimeSpan();

              MissingImport

              Since: 2.7.0

              Importing all external classes in a file through use statements makes them clearly visible.

              Example

              function make() {
                  return new \stdClass();
              }

              Source http://phpmd.org/rules/cleancode.html#MissingImport

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Months'] != 1) ? QApplication::Translate('about %s months') : QApplication::Translate('a month');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Seconds'] != 1) ? QApplication::Translate('%s seconds') : QApplication::Translate('a second');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Years'] != 1) ? QApplication::Translate('about %s years') :  QApplication::Translate('a year');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Months'] != 1) ? QApplication::Translate('about %s months') : QApplication::Translate('a month');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Days'] != 1) ? QApplication::Translate('about %s days') : QApplication::Translate('a day');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Seconds'] != 1) ? QApplication::Translate('%s seconds') : QApplication::Translate('a second');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Days'] != 1) ? QApplication::Translate('about %s days') : QApplication::Translate('a day');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Minutes'] != 1) ? QApplication::Translate('%s minutes') : QApplication::Translate('a minute');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Years'] != 1) ? QApplication::Translate('about %s years') :  QApplication::Translate('a year');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QType' in method '__set'.
              Open

                                      return ($this->intSeconds = QType::Cast($mixValue, QType::Integer));

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Hours'] != 1) ? QApplication::Translate('about %s hours') : QApplication::Translate('an hour');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Hours'] != 1) ? QApplication::Translate('about %s hours') : QApplication::Translate('an hour');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class 'QApplication' in method 'SimpleDisplay'.
              Open

                              $strFormat = ($arrTimearray['Minutes'] != 1) ? QApplication::Translate('%s minutes') : QApplication::Translate('a minute');

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Constant SecondsPerYear should be defined in uppercase
              Open

                       const SecondsPerYear    = 31556926;

              ConstantNamingConventions

              Since: 0.2

              Class/Interface constant names should always be defined in uppercase.

              Example

              class Foo {
                  const MY_NUM = 0; // ok
                  const myTest = ""; // fail
              }

              Source https://phpmd.org/rules/naming.html#constantnamingconventions

              Constant SecondsPerMonth should be defined in uppercase
              Open

                       const SecondsPerMonth     = 2592000;

              ConstantNamingConventions

              Since: 0.2

              Class/Interface constant names should always be defined in uppercase.

              Example

              class Foo {
                  const MY_NUM = 0; // ok
                  const myTest = ""; // fail
              }

              Source https://phpmd.org/rules/naming.html#constantnamingconventions

              Constant SecondsPerHour should be defined in uppercase
              Open

                      const SecondsPerHour     = 3600;

              ConstantNamingConventions

              Since: 0.2

              Class/Interface constant names should always be defined in uppercase.

              Example

              class Foo {
                  const MY_NUM = 0; // ok
                  const myTest = ""; // fail
              }

              Source https://phpmd.org/rules/naming.html#constantnamingconventions

              Constant SecondsPerMinute should be defined in uppercase
              Open

                      const SecondsPerMinute     = 60;

              ConstantNamingConventions

              Since: 0.2

              Class/Interface constant names should always be defined in uppercase.

              Example

              class Foo {
                  const MY_NUM = 0; // ok
                  const myTest = ""; // fail
              }

              Source https://phpmd.org/rules/naming.html#constantnamingconventions

              Constant SecondsPerDay should be defined in uppercase
              Open

                      const SecondsPerDay     = 86400;

              ConstantNamingConventions

              Since: 0.2

              Class/Interface constant names should always be defined in uppercase.

              Example

              class Foo {
                  const MY_NUM = 0; // ok
                  const myTest = ""; // fail
              }

              Source https://phpmd.org/rules/naming.html#constantnamingconventions

              The method Subtract is not named in camelCase.
              Open

                      public function Subtract(QDateTimeSpan $dtsSpan){
                          $this->intSeconds = $this->intSeconds - $dtsSpan->Seconds;
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method SimpleDisplay is not named in camelCase.
              Open

                      public function SimpleDisplay(){
                          $arrTimearray = $this->GetTimearray();
                          $strToReturn = null;
              
                          if($arrTimearray['Years'] != 0) {

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method Difference is not named in camelCase.
              Open

                      public function Difference(QDateTimeSpan $dtsSpan){
                          $intDifference = $this->Seconds - $dtsSpan->Seconds;
                          $dtsDateSpan = new QDateTimeSpan();
                          $dtsDateSpan->AddSeconds($intDifference);
                          return $dtsDateSpan;

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method SetFromQDateTime is not named in camelCase.
              Open

                      public function SetFromQDateTime(QDateTime $dttFrom, QDateTime $dttTo){
                          $this->Add($dttFrom->Difference($dttTo));
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method AddDays is not named in camelCase.
              Open

                      public function AddDays($intDays){
                          $this->intSeconds = $this->intSeconds + ($intDays * QDateTimeSpan::SecondsPerDay);
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method AddMonths is not named in camelCase.
              Open

                      public function AddMonths($intMonths){
                          $this->intSeconds = $this->intSeconds + ($intMonths * QDateTimeSpan::SecondsPerMonth);
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method GetTimearray is not named in camelCase.
              Open

                      protected function GetTimearray(){
                          $intSeconds = abs($this->intSeconds);
              
                          $intYears = floor($intSeconds / QDateTimeSpan::SecondsPerYear);
                          $intSeconds = $intSeconds - ($intYears * QDateTimeSpan::SecondsPerYear);

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method IsNegative is not named in camelCase.
              Open

                      public function IsNegative(){
                          return ($this->intSeconds < 0);
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method GetHours is not named in camelCase.
              Open

                      protected function GetHours(){
                          $intSecondsPerHour = ($this->IsPositive()) ? QDateTimeSpan::SecondsPerHour : ((-1) * QDateTimeSpan::SecondsPerHour);
                          $intHours = floor($this->intSeconds / $intSecondsPerHour);
                          if($this->IsNegative()) $intHours = (-1) * $intHours;
                          return $intHours;

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method GetMonths is not named in camelCase.
              Open

                      protected function GetMonths(){
                          $intSecondsPerMonth = ($this->IsPositive()) ? QDateTimeSpan::SecondsPerMonth : ((-1) * QDateTimeSpan::SecondsPerMonth);
                          $intMonths = floor($this->intSeconds / $intSecondsPerMonth);
                          if($this->IsNegative()) $intMonths = (-1) * $intMonths;
                          return $intMonths;

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method GetDays is not named in camelCase.
              Open

                      protected function GetDays(){
                          $intSecondsPerDay = ($this->IsPositive()) ? QDateTimeSpan::SecondsPerDay : ((-1) * QDateTimeSpan::SecondsPerDay);
                          $intDays = floor($this->intSeconds / $intSecondsPerDay);
                          if($this->IsNegative()) $intDays = (-1) * $intDays;
                          return $intDays;

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method GetMinutes is not named in camelCase.
              Open

                      protected function GetMinutes(){
                          $intSecondsPerMinute = ($this->IsPositive()) ? QDateTimeSpan::SecondsPerMinute : ((-1) * QDateTimeSpan::SecondsPerMinute);
                          $intMinutes = floor($this->intSeconds / $intSecondsPerMinute);
                          if($this->IsNegative()) $intMinutes = (-1) * $intMinutes;
                          return $intMinutes;

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method AddMinutes is not named in camelCase.
              Open

                      public function AddMinutes($intMinutes){
                          $this->intSeconds = $this->intSeconds + ($intMinutes * QDateTimeSpan::SecondsPerMinute);
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method IsPositive is not named in camelCase.
              Open

                      public function IsPositive(){
                          return ($this->intSeconds > 0);
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method AddSeconds is not named in camelCase.
              Open

                      public function AddSeconds($intSeconds){
                          $this->intSeconds = $this->intSeconds + $intSeconds;
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method AddHours is not named in camelCase.
              Open

                      public function AddHours($intHours){
                          $this->intSeconds = $this->intSeconds + ($intHours * QDateTimeSpan::SecondsPerHour);
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method Add is not named in camelCase.
              Open

                      public function Add(QDateTimeSpan $dtsSpan){
                          $this->intSeconds = $this->intSeconds + $dtsSpan->Seconds;
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method IsZero is not named in camelCase.
              Open

                      public function IsZero(){
                          return ($this->intSeconds == 0);
                      }

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              The method GetYears is not named in camelCase.
              Open

                      protected function GetYears() {
                          $intSecondsPerYear = ($this->IsPositive()) ? QDateTimeSpan::SecondsPerYear : ((-1) * QDateTimeSpan::SecondsPerYear);
                          $intYears = floor($this->intSeconds / $intSecondsPerYear);
                          if ($this->IsNegative()) $intYears = (-1) * $intYears;
                          return $intYears;

              CamelCaseMethodName

              Since: 0.2

              It is considered best practice to use the camelCase notation to name methods.

              Example

              class ClassName {
                  public function get_name() {
                  }
              }

              Source

              There are no issues that match your filters.

              Category
              Status