Showing 117 of 118 total issues
The method matchYearCondition() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
protected function matchYearCondition($dateTime, ?string &$condition): bool
{
if (!$condition || !preg_match(
'/^\s*year(?:\s*%\s*(?<modulo>\d+))?\s*(?<operator>>=?|<=?|={1,3}|!={1,2}|<>)\s*(?<expected>\d+)/',
$condition,
- Read upRead up
- Exclude checks
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
The method isIgnoredYear() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
protected function isIgnoredYear(&$holiday)
{
$mode = 'since';
$cap = 0;
$every = 0;
- Read upRead up
- Exclude checks
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
Line exceeds 120 characters; contains 121 characters Open
return static function (string $region, ?iterable $holidays = null, ?iterable $workingDays = null) use ($mixin) {
- 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 153 characters Open
* @param int $year input year, year of the current instance or context used if omitted, current year used if omitted and called statically
- 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 128 characters Open
* @param string $type can be 'string' (to return dates as string) or a class name to returns instances of this class
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
* @param string $type can be 'string' (to return dates as string) or a class name to returns instances of this class
- 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 153 characters Open
* @param int $year input year, year of the current instance or context used if omitted, current year used if omitted and called statically
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
static function ($file) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 20 Open
},
- Exclude checks
Argument 1 (mixin)
is \Cmixin\BusinessDay\Holiday|\Cmixin\BusinessDay\HolidayData|\Cmixin\BusinessDay\HolidaysList|\Cmixin\BusinessDay\MixinBase|\Cmixin\BusinessDay\YearCrawler
but \Cmixin\BusinessDay\Calculator\MixinConfigPropagator::setHolidayGetter()
takes \Cmixin\BusinessDay\BusinessCalendar
defined at /code/src/Cmixin/BusinessDay/Calculator/MixinConfigPropagator.php:56
Open
$mixin,
- Exclude checks
Expression may not be PHP 7 compatible Open
if (!$region || !isset($mixin->$list[$region])) {
- Exclude checks
Cannot access internal method \Cmixin\BusinessDay\Calculator\HolidayCalculator::__construct()
of namespace \Cmixin\BusinessDay\Calculator
defined at /code/src/Cmixin/BusinessDay/Calculator/HolidayCalculator.php:41
from namespace \Cmixin\BusinessDay
Open
$calculator = new HolidayCalculator((int) $year, $type, $holidays);
- Exclude checks
Add a "case default" clause to this "switch" statement. Open
switch ($match[0]) {
- Read upRead up
- Exclude checks
The requirement for a final case default
clause is defensive programming. The clause should either take appropriate action, or contain
a suitable comment as to why no action is taken. Even when the switch
covers all current values of an enum
, a default case
should still be used because there is no guarantee that the enum
won't be extended.
Noncompliant Code Example
switch ($param) { //missing default clause case 0: do_something(); break; case 1: do_something_else(); break; } switch ($param) { default: // default clause should be the last one error(); break; case 0: do_something(); break; case 1: do_something_else(); break; }
Compliant Solution
switch ($param) { case 0: do_something(); break; case 1: do_something_else(); break; default: error(); break; }
See
- MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
- MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
- MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
- MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
- MISRA C:2012, 16.1 - All switch statements shall be well-formed
- MISRA C:2012, 16.4 - Every switch statement shall have a default label
- MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
- MITRE, CWE-478 - Missing Default Case in Switch Statement
- CERT, MSC01-C. - Strive for logical completeness
- CERT, MSC01-CPP. - Strive for logical completeness
Rename "$outputClass" which has the same name as the field declared at line 24. Open
$outputClass = $this->outputClass;
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Cannot access internal method \Cmixin\BusinessDay\BusinessMonth::getStart()
of namespace \Cmixin\BusinessDay
defined at /code/src/Cmixin/BusinessDay/BusinessMonth.php:39
from namespace \Cmixin
Open
$date = $month->getStart();
- Exclude checks
Instantiation of abstract class \Cmixin\BusinessDay\Calendar\AlternativeCalendar
Open
static::$singletons[$name] = new static();
- Exclude checks
Possibly zero references to use statement for classlike/namespace BusinessDay
(\Cmixin\BusinessDay)
Open
use Cmixin\BusinessDay;
- Exclude checks