kylekatarnls/business-day

View on GitHub

Showing 117 of 118 total issues

Avoid variables with short names like $id. Configured minimum length is 3.
Open

        return static function (string $id, array $data) use ($mixin) {

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Avoid variables with short names like $id. Configured minimum length is 3.
Open

        return static function (string $id, array $data) use ($mixin) {

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Avoid variables with short names like $id. Configured minimum length is 3.
Open

        return static function (string $id) use ($mixin): ?array {

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Avoid variables with short names like $id. Configured minimum length is 3.
Open

        return static function (string $id) use ($mixin): ?array {

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Avoid variables with short names like $to. Configured minimum length is 3.
Open

    public static function propagate($from, $to): void

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Function getHolidayDate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getHolidayDate($key, $holiday)
    {
        $year = $this->year;

        if ($key === null) {
Severity: Minor
Found in src/Cmixin/BusinessDay/Calculator/HolidayCalculator.php - About 45 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 handleModifiers has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    protected function handleModifiers($dateTime, $condition, $substitute, $after, $before)
Severity: Minor
Found in src/Cmixin/BusinessDay/Calculator/HolidayCalculator.php - About 35 mins to fix

    Function isIgnoredYear has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function isIgnoredYear(&$holiday)
        {
            $mode = 'since';
            $cap = 0;
            $every = 0;
    Severity: Minor
    Found in src/Cmixin/BusinessDay/Calculator/CalculatorBase.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 handleModifiers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function handleModifiers($dateTime, $condition, $substitute, $after, $before)
        {
            if ($condition && ($action = $this->getConditionalModifier(explode(' and ', $condition), $dateTime))) {
                $dateTime = $dateTime->modify($action);
            }
    Severity: Minor
    Found in src/Cmixin/BusinessDay/Calculator/HolidayCalculator.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

    The method skipMissingCalendarExtensionException has a boolean flag argument $skipped, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public static function skipMissingCalendarExtensionException(bool $skipped = true): void
    Severity: Minor
    Found in src/Cmixin/BusinessDay/MixinBase.php by phpmd

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

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

    Avoid too many return statements within this method.
    Open

                    return $value === $expected;
    Severity: Major
    Found in src/Cmixin/BusinessDay/Util/YearCondition.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                      return $value <= $expected;
      Severity: Major
      Found in src/Cmixin/BusinessDay/Util/YearCondition.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return $value !== $expected;
        Severity: Major
        Found in src/Cmixin/BusinessDay/Util/YearCondition.php - About 30 mins to fix

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

              public function initializeHolidaysRegion($region = null)
              {
                  if ($region) {
                      $region = call_user_func($this->standardizeHolidaysRegion(), $region);
          
          
          Severity: Minor
          Found in src/Cmixin/BusinessDay/HolidaysList.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 boot has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function boot()
              {
                  $config = $this->app->get('config')->get('carbon.holidays');
          
                  if ($config instanceof Closure) {
          Severity: Minor
          Found in src/Cmixin/BusinessDay/Laravel/ServiceProvider.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

          Avoid using static access to class '\Illuminate\Support\Facades\Date' in method 'boot'.
          Open

                          (($now = Date::now()) instanceof DateTimeInterface) &&

          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 '\Cmixin\BusinessDay\Util\FileConfig' in method 'setHolidaysRegion'.
          Open

                                  FileConfig::use($file, $mixin, $nation);

          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 assigning values to variables in if clauses and the like (line '104', column '42').
          Open

              public function setHolidaysRegion()
              {
                  $mixin = $this;
          
                  /**

          IfStatementAssignment

          Since: 2.7.0

          Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($foo = 'bar') { // possible typo
                      // ...
                  }
                  if ($baz = 0) { // always false
                      // ...
                  }
              }
          }

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

          Avoid using static access to class '\Cmixin\BusinessDay\Util\Context' in method 'setHolidayObserveStatus'.
          Open

                      return isset($this) && Context::isNotMixin($this, $mixin) ? $this : (isset($self) ? $self : null);

          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 assigning values to variables in if clauses and the like (line '30', column '19').
          Open

              public function boot()
              {
                  $config = $this->app->get('config')->get('carbon.holidays');
          
                  if ($config instanceof Closure) {

          IfStatementAssignment

          Since: 2.7.0

          Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($foo = 'bar') { // possible typo
                      // ...
                  }
                  if ($baz = 0) { // always false
                      // ...
                  }
              }
          }

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

          Severity
          Category
          Status
          Source
          Language