Showing 227 of 228 total issues
Avoid assigning values to variables in if clauses and the like (line '57', column '15'). Open
private function getCarbonClasses(): array
{
$classes = array_filter([
Carbon::class,
CarbonImmutable::class,
- 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 'BusinessTime\Normalizer' in method 'convertOpeningHours'. Open
: Normalizer::normalizeDay($key);
- 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
The method parseMethodDoc() has an NPath complexity of 219. The configured NPath complexity threshold is 200. Open
private function parseMethodDoc(
string $name,
int $length,
string $className,
string $defaultClass,
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method calculateFloatDiff() has an NPath complexity of 1152. The configured NPath complexity threshold is 200. Open
public function calculateFloatDiff(CarbonInterface $start, CarbonInterface $end): float
{
if ($end < $start) {
return ($this->absolute ? 1 : -1) * $this->calculateFloatDiff($end, $start);
}
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method getScheduleDoc() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function getScheduleDoc($defaultClass, $source, $boot)
{
$methods = [];
$source = str_replace('\\', '/', realpath($source));
$sourceLength = strlen($source);
- 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 getOpeningHours() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function getOpeningHours($mode = null, $context = null)
{
switch ($mode) {
case static::GLOBAL_MODE:
return $this->openingHours;
- 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 parseMethodDoc() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
private function parseMethodDoc(
string $name,
int $length,
string $className,
string $defaultClass,
- 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 calculateFloatDiff() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function calculateFloatDiff(CarbonInterface $start, CarbonInterface $end): float
{
if ($end < $start) {
return ($this->absolute ? 1 : -1) * $this->calculateFloatDiff($end, $start);
}
- 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 246 characters Open
* @method \Spatie\OpeningHours\OpeningHours getOpeningHours(CarbonInterface $date, $mode = null) Get the opening hours of the class/instance.
- Exclude checks
Line exceeds 120 characters; contains 260 characters Open
* @method mixed safeCallOnOpeningHours(CarbonInterface $date, $method, ...$arguments) Call a method on the OpeningHours of the current instance.
- Exclude checks
Line exceeds 120 characters; contains 310 characters Open
* @method \Carbon\Carbon|\Carbon\CarbonImmutable|\Carbon\CarbonInterface getMethodLoopOnHoliday(CarbonInterface $date) Loop on the current instance (or now if called statically) with a given method until it's not a holiday.
- Exclude checks
Line exceeds 120 characters; contains 256 characters Open
* @method \Carbon\CarbonInterface|\Carbon\Carbon|\Carbon\CarbonImmutable currentOrPreviousBusinessDay(CarbonInterface $date) Sets the date to the current or previous business day.
- Exclude checks
Line exceeds 120 characters; contains 249 characters Open
* @method $this|null observeHoliday(CarbonInterface $date, $holidayId = null, $observed = null, $self = null) Set a holiday as observed in the selected zone.
- Exclude checks
Line exceeds 120 characters; contains 301 characters Open
* @method \Carbon\Carbon|\Carbon\CarbonImmutable|\Carbon\CarbonInterface|null addHoliday(CarbonInterface $date, $region, $holiday, $holidayId = null, $name = null, $observed = null) Add a holiday to the holidays list of a region and optionally init its ID, name and observed state.
- Exclude checks
Line exceeds 120 characters; contains 269 characters Open
* @method \Carbon\Carbon|\Carbon\CarbonImmutable|\Carbon\CarbonInterface addClosedHours(CarbonInterface $date, int $numberOfHours, int $options = 0) Add the given number of hours taking into account only closed time.
- Exclude checks
Line exceeds 120 characters; contains 236 characters Open
* @method \Carbon\Carbon|\Carbon\CarbonImmutable|\Carbon\CarbonInterface nextOpen(CarbonInterface $date, $method = null) Go to the next open date and time.
- Exclude checks
Line exceeds 120 characters; contains 271 characters Open
* @method \Carbon\Carbon|\Carbon\CarbonImmutable|\Carbon\CarbonInterface openOrNextCloseIncludingHolidays(CarbonInterface $date) Return current date-time if it's open, else go to the next close date
- Exclude checks
Line exceeds 120 characters; contains 283 characters Open
* @method \Carbon\CarbonInterface|\Carbon\Carbon|\Carbon\CarbonImmutable nextBusinessDay(CarbonInterface $date) Sets the date to the next business day (neither a weekend day nor a holiday).
- Exclude checks
Line exceeds 120 characters; contains 249 characters Open
* @method $this|null observeHolidays(CarbonInterface $date, $holidayId = null, $observed = null, $self = null) Set a holiday as observed in the selected zone.
- Exclude checks
Line exceeds 120 characters; contains 251 characters Open
* @method array getHolidays(CarbonInterface $date, $region = null) Get the holidays for the current region selected.
- Exclude checks