Showing 117 of 118 total issues
Expression may not be PHP 7 compatible Open
return $mixin->$list[$region];
- Exclude checks
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
Expression may not be PHP 7 compatible Open
if (!isset($this->$list[$region])) {
- Exclude checks
Rename "$holidayGetter" which has the same name as the field declared at line 24. Open
$holidayGetter = MixinConfigPropagator::getHolidayGetter($mixin, $self);
- 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
Expression may not be PHP 7 compatible Open
: ($mixin->$list[$region][] = $day);
- 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
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.
Cannot access internal method \Cmixin\BusinessDay\BusinessMonth::__construct()
of namespace \Cmixin\BusinessDay
defined at /code/src/Cmixin/BusinessDay/BusinessMonth.php:24
from namespace \Cmixin
Open
$month = new BusinessMonth($date ?? $self, get_class($self));
- Exclude checks
Possibly zero references to use statement for classlike/namespace BusinessDay
(\Cmixin\BusinessDay)
Open
use Cmixin\BusinessDay;
- Exclude checks
Cannot access internal method \Cmixin\BusinessDay\Calculator\HolidayCalculator::setHolidaysList()
of namespace \Cmixin\BusinessDay\Calculator
defined at /code/src/Cmixin/BusinessDay/Calculator/HolidayCalculator.php:66
from namespace \Cmixin\BusinessDay
Open
$calculator->setHolidaysList($holidaysList);
- Exclude checks
Rename "$workdayGetter" which has the same name as the field declared at line 34. Open
$workdayGetter = MixinConfigPropagator::getExtraWorkdayGetter($mixin, $self);
- 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::getEnd()
of namespace \Cmixin\BusinessDay
defined at /code/src/Cmixin/BusinessDay/BusinessMonth.php:47
from namespace \Cmixin
Open
return $month->getStart()->diffInBusinessDays($month->getEnd());
- Exclude checks
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
return $month->getStart()->diffInBusinessDays($month->getEnd());
- Exclude checks
Call with 3 arg(s) to \Cmixin\BusinessDay::swapDateTimeParam()
which only takes 0 arg(s) defined at /code/src/Cmixin/BusinessDay/MixinBase.php:59
Open
[$days, $date] = static::swapDateTimeParam($days, $date, null);
- Exclude checks
Returning type \Cmixin\BusinessDay\HolidayObserver
but Closure($holidayId, $observed, $self = null)
is declared to return null|static
Open
return isset($this) && Context::isNotMixin($this, $mixin) ? $this : (isset($self) ? $self : null);
- Exclude checks
Expression may not be PHP 7 compatible Open
if (!$region || !isset($mixin->$list[$region])) {
- Exclude checks
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