Showing 27 of 27 total issues
Method makeAstDiff
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
function makeAstDiff($data1, $data2): array
{
$makeDiff = function ($data1, $data2) use (&$makeDiff): array {
$nodesNames = array_keys(array_merge((array)$data1, (array)$data2));
Method format
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
function format(array $diff): string
{
$format = function ($diff, $level) use (&$format) {
return array_map(
function ($node) use ($level, $format) {
Avoid excessively long variable names like $stringifyComplexValue. Keep variable name length under 20. Open
$stringifyComplexValue = fn($complexValue, $level) => implode(
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Method format
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function format(array $diff): string
{
$format = function ($nodes, $nodePath) use (&$format) {
return array_map(function ($node) use ($format, $nodePath) {
[
Method formatMessage
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function formatMessage(int $indentLevel, string $mark, string $nodeName, $value): string
{
$stringifyComplexValue = fn($complexValue, $level) => implode(
END_OF_LINE,
[
There must be one USE keyword per declaration Open
use const GenDiff\Diff\{ADDED, CHANGED, NESTED, REMOVED, UNCHANGED};
- Exclude checks
There must be one USE keyword per declaration Open
use const GenDiff\Diff\{ADDED, CHANGED, NESTED, REMOVED, UNCHANGED};
- Exclude checks
The method makeAstDiff uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return makeNode([
'type' => CHANGED,
'name' => $nodeName,
'oldValue' => $data1->$nodeName,
- 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 ''''. Open
compactCollection(flatten($format($diff, '')))
- 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
Avoid using static access to class '\Symfony\Component\Yaml\Yaml' in method 'parseYaml'. Open
return Yaml::parse($data, Yaml::PARSE_OBJECT_FOR_MAP);
- 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 function makeAstDiff() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
function makeAstDiff($data1, $data2): array
{
$makeDiff = function ($data1, $data2) use (&$makeDiff): array {
$nodesNames = array_keys(array_merge((array)$data1, (array)$data2));
- 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
Only one argument is allowed per line in a multi-line function call Open
fn($value, $key) => formatMessage($indentLevel + 1, MARK_SPACES, $key, $value),
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
fn($value, $key) => formatMessage($indentLevel + 1, MARK_SPACES, $key, $value),
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
fn($value, $key) => formatMessage($indentLevel + 1, MARK_SPACES, $key, $value),
- Exclude checks
syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
Open
'yaml' => fn($content) => parseYaml($content),
- Exclude checks
syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
Open
REMOVED => fn() => sprintf("Property '%s' was removed", $ascendantNodePath),
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
-h --help Show this screen
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
--format <fmt> Report format [default: stylish] Examples: stylish, plain, json
- Exclude checks
Expected an indentation at 8 instead of at 6. Open
"ext-json": "*"
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
gendiff [--format <fmt>] <firstFile> <secondFile>
- Exclude checks