Showing 77 of 86 total issues
Function guessDateTime
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Confirmed
public function guessDateTime($timestring)
{
$date_time = explode(' ', $timestring);
$date = explode('/', $date_time[0]);
- 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 guessDateTime
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Confirmed
public function guessDateTime($timestring)
{
$date_time = explode(' ', $timestring);
$date = explode('/', $date_time[0]);
Method setIntlDateFormatter
has 6 arguments (exceeds 4 allowed). Consider refactoring. Confirmed
$locale = 'en_US',
$datetype = IntlDateFormatter::FULL,
$timetype = IntlDateFormatter::FULL,
$timezone = 'UTC',
$calendar = IntlDateFormatter::GREGORIAN,
Avoid too many return
statements within this method. Confirmed
return [$year, $month, $day, $hour, $minute, $second];
Avoid too many return
statements within this method. Confirmed
return false;
The method parseDateTime() has an NPath complexity of 8192. The configured NPath complexity threshold is 200. Confirmed
private function parseDateTime($datetimeArray)
{
$finalDatetimeArray = [];
if (!is_array($datetimeArray)) {
- 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 to uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Confirmed
} else {
$this->setFinalCalendarType(IntlDateFormatter::TRADITIONAL);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused local variables such as '$utcDT'. Confirmed
$utcDT = gmdate('c', $timestamp);
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
The method guessDateTime() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10. Confirmed
public function guessDateTime($timestring)
{
$date_time = explode(' ', $timestring);
$date = explode('/', $date_time[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
The method parseDateTime() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Confirmed
private function parseDateTime($datetimeArray)
{
$finalDatetimeArray = [];
if (!is_array($datetimeArray)) {
- 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 152 characters Open
$this->getIntlCalendar()->set($datetimeArray[0], $datetimeArray[1], $datetimeArray[2], $datetimeArray[3], $datetimeArray[4], $datetimeArray[5]);
- Exclude checks
Line exceeds 120 characters; contains 166 characters Open
$timestamp = mktime(date('H', $timestamp), date('i', $timestamp), date('s', $timestamp), date('n', $timestamp), date('j', $timestamp), date('Y', $timestamp));
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
throw new Exception('DateTime information must be an array in [year, month, day, hours, minutes, seconds] format.');
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
$finalDatetimeArray[2] = isset($datetimeArray[2]) ? (int) $datetimeArray[2] : (isset($datetimeArray['mday']) ? (int) $datetimeArray['mday'] : 1);
- Exclude checks
Line exceeds 120 characters; contains 156 characters Open
$finalDatetimeArray[0] = isset($datetimeArray[0]) ? (int) $datetimeArray[0] : (isset($datetimeArray['year']) ? (int) $datetimeArray['year'] : 1970);
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
$finalDatetimeArray[1] = isset($datetimeArray[1]) ? (int) $datetimeArray[1] - 1 : (isset($datetimeArray['mon']) ? (int) $datetimeArray['mon'] - 1 : 0);
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
$finalDatetimeArray[4] = isset($datetimeArray[4]) ? (int) $datetimeArray[4] : (isset($datetimeArray['minutes']) ? (int) $datetimeArray['minutes'] : 0);
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
$finalDatetimeArray[5] = isset($datetimeArray[5]) ? (int) $datetimeArray[5] : (isset($datetimeArray['seconds']) ? (int) $datetimeArray['seconds'] : 0);
- Exclude checks
Line exceeds 120 characters; contains 155 characters Open
$finalDatetimeArray[3] = isset($datetimeArray[3]) ? (int) $datetimeArray[3] : (isset($datetimeArray['hours']) ? (int) $datetimeArray['hours'] : 0);
- Exclude checks
Trailing spaces Open
- Read upRead up
- Exclude checks
MD009 - Trailing spaces
Tags: whitespace
Aliases: no-trailing-spaces
Parameters: br_spaces (number; default: 0)
This rule is triggered on any lines that end with whitespace. To fix this, find the line that is triggered and remove any trailing spaces from the end.
The brspaces parameter allows an exception to this rule for a specific amount of trailing spaces used to insert an explicit line break/br element. For example, set brspaces to 2 to allow exactly 2 spaces at the end of a line.
Note: you have to set brspaces to 2 or higher for this exception to take effect - you can't insert a br element with just a single trailing space, so if you set brspaces to 1, the exception will be disabled, just as if it was set to the default of 0.