Completed
Push — master ( 002f3e...7bdf3e )
by T
01:42
created

Node::isEqual()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7.0796

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 15
cts 17
cp 0.8824
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 18
nc 7
nop 2
crap 7.0796
1
<?php
2
3
namespace PHPSemVerChecker\Comparator;
4
5
class Node
6
{
7
	/**
8
	 * @param \PhpParser\Node $nodeA
9
	 * @param \PhpParser\Node $nodeB
10
	 * @return bool
11
	 */
12 10
	public static function isEqual(\PhpParser\Node $nodeA, \PhpParser\Node $nodeB)
13
	{
14 10
		if ($nodeA->getType() !== $nodeB->getType()) {
15
			return false;
16
		}
17
18 10
		$subNodesA = $nodeA->getSubNodeNames();
19 10
		$subNodesB = $nodeB->getSubNodeNames();
20 10
		if ($subNodesA !== $subNodesB) {
21
			return false;
22
		}
23
24 10
		foreach ($subNodesA as $key) {
25 10
			$valueA = $nodeA->$key;
26 10
			$valueB = $nodeB->$key;
27 10
			$result = true;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28 10
			if ($valueA instanceof \PhpParser\Node && $valueB instanceof \PhpParser\Node) {
29 1
				$result = self::isEqual($valueA, $valueB);
30
			} else {
31 10
				$result = $valueA === $valueB;
32
			}
33
34 10
			if ( ! $result) {
35 10
				return false;
36
			}
37
		}
38
39 1
		return true;
40
	}
41
}
42