kylekatarnls/business-day

View on GitHub
src/Cmixin/BusinessDay/HolidaysList.php

Summary

Maintainability
B
5 hrs
Test Coverage
A
100%

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

class HolidaysList extends MixinBase
{
    /**
     * @var array
     */

The class HolidaysList has 11 public methods. Consider refactoring HolidaysList to keep number of public methods under 10.
Open

class HolidaysList extends MixinBase
{
    /**
     * @var array
     */

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

File HolidaysList.php has 279 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Cmixin\BusinessDay;

use Cmixin\BusinessDay\Util\Context;
Severity: Minor
Found in src/Cmixin/BusinessDay/HolidaysList.php - About 2 hrs to fix

    Function setHolidaysRegion has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        public function setHolidaysRegion()
        {
            $mixin = $this;
    
            /**
    Severity: Minor
    Found in src/Cmixin/BusinessDay/HolidaysList.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 setHolidaysRegion has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function setHolidaysRegion()
        {
            $mixin = $this;
    
            /**
    Severity: Minor
    Found in src/Cmixin/BusinessDay/HolidaysList.php - About 1 hr to fix

      Function setHolidayName has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Wontfix

          public function setHolidayName()
          {
              $mixin = $this;
      
              /**
      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 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

      Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
      Open

          public function setHolidaysRegion()

      Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

      See

      Avoid using static access to class '\Cmixin\BusinessDay\Util\FileConfig' in method 'setHolidaysRegion'.
      Open

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

      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\Context' in method 'pushToBDList'.
      Open

                  return isset($this) && Context::isNotMixin($this, $mixin) ? $this : 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 using static access to class '\Cmixin\BusinessDay\Util\Context' in method 'addHoliday'.
      Open

                  return isset($this) && Context::isNotMixin($this, $mixin) ? $this : 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 '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 'pushWorkday'.
      Open

                  return isset($this) && Context::isNotMixin($this, $mixin) ? $this : 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 using static access to class '\Cmixin\BusinessDay\Util\Context' in method 'addExtraWorkday'.
      Open

                  return isset($this) && Context::isNotMixin($this, $mixin) ? $this : 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 using static access to class '\Cmixin\BusinessDay\Util\FileConfig' in method 'setHolidaysRegion'.
      Open

                              FileConfig::use(__DIR__."/../Holidays/$region.php", $mixin, $region);

      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\Context' in method 'pushHoliday'.
      Open

                  return isset($this) && Context::isNotMixin($this, $mixin) ? $this : 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 using static access to class '\Cmixin\BusinessDay\Util\Context' in method 'setHolidayName'.
      Open

                  return isset($this) && Context::isNotMixin($this, $mixin) ? $this : 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 '99', column '34').
      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 assigning values to variables in if clauses and the like (line '416', column '47').
      Open

          public function setHolidayName()
          {
              $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\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

      Define a constant instead of duplicating this literal "workdays" 4 times.
      Open

                  if (!in_array($list, ['holidays', 'workdays'])) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "holidays" 4 times.
      Open

                  if (!in_array($list, ['holidays', 'workdays'])) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "regions" 3 times.
      Open

                          if (isset($mixin->holidays[$nation]['regions'], $mixin->holidays[$nation]['regions'][$subRegion])) {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Expression may not be PHP 7 compatible
      Open

                  if (!$region || !isset($mixin->$list[$region])) {

      Expression may not be PHP 7 compatible
      Open

                      if (!isset($this->$list[$region])) {

      Expression may not be PHP 7 compatible
      Open

                  return $mixin->$list[$region];

      Expression may not be PHP 7 compatible
      Open

                          $this->$list[$region] = [];

      Expression may not be PHP 7 compatible
      Open

                      ? ($mixin->$list[$region][$dayId] = $day)

      Expression may not be PHP 7 compatible
      Open

                      : ($mixin->$list[$region][] = $day);

      Line exceeds 120 characters; contains 129 characters
      Open

              return static function ($region, $holiday, $holidayId = null, $name = null, $observed = null) use ($mixin, $dictionary) {

      Line exceeds 120 characters; contains 149 characters
      Open

               * @param string|array $language   language 2-chars code (or an array with languages codes as keys and new names for each language as value).

      Line exceeds 120 characters; contains 150 characters
      Open

               * Add a holiday to the holidays list of a region and optionally init their IDs, names and observed states (if provided as array-definitions).

      Line exceeds 120 characters; contains 121 characters
      Open

              return static function (string $region, ?iterable $holidays = null, ?iterable $workingDays = null) use ($mixin) {

      Line indented incorrectly; expected 16 spaces, found 20
      Open

                          },

      Line indented incorrectly; expected 16 spaces, found 20
      Open

                          static function ($file) {

      There are no issues that match your filters.

      Category
      Status