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
*/
- Exclude checks
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
*/
- Read upRead up
- Exclude checks
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;
Function setHolidaysRegion
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function setHolidaysRegion()
{
$mixin = $this;
/**
- Read upRead up
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;
/**
Function setHolidayName
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Wontfix
public function setHolidayName()
{
$mixin = $this;
/**
- Read upRead up
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);
- Read upRead up
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()
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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;
/**
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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;
/**
- Read upRead up
- Exclude checks
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;
/**
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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'])) {
- Read upRead up
- Exclude checks
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'])) {
- Read upRead up
- Exclude checks
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])) {
- Read upRead up
- Exclude checks
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])) {
- Exclude checks
Expression may not be PHP 7 compatible Open
if (!isset($this->$list[$region])) {
- Exclude checks
Expression may not be PHP 7 compatible Open
return $mixin->$list[$region];
- Exclude checks
Expression may not be PHP 7 compatible Open
$this->$list[$region] = [];
- Exclude checks
Expression may not be PHP 7 compatible Open
? ($mixin->$list[$region][$dayId] = $day)
- Exclude checks
Expression may not be PHP 7 compatible Open
: ($mixin->$list[$region][] = $day);
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
return static function ($region, $holiday, $holidayId = null, $name = null, $observed = null) use ($mixin, $dictionary) {
- Exclude checks
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).
- Exclude checks
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).
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
return static function (string $region, ?iterable $holidays = null, ?iterable $workingDays = null) use ($mixin) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
},
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
static function ($file) {
- Exclude checks