Completed
Push — master ( 0e1c32...e580ff )
by T
05:02
created

Signature::requiredParametersChanges()   C

Complexity

Conditions 7
Paths 14

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
ccs 0
cts 13
cp 0
rs 6.9811
cc 7
eloc 11
nc 14
nop 2
crap 56
1
<?php
2
3
namespace PHPSemVerChecker\Comparator;
4
5
class Signature {
6
	/**
7
	 * @param array $parametersA
8
	 * @param array $parametersB
9
	 * @return array
10
	 */
11 72
	public static function analyze(array $parametersA, array $parametersB)
12
	{
13
		$changes = [
14 72
			'parameter_added' => false,
15
			'parameter_removed' => false,
16
			'parameter_renamed' => false,
17
			'parameter_typing_added' => false,
18
			'parameter_typing_removed' => false,
19
			'parameter_default_added' => false,
20
			'parameter_default_removed' => false,
21
			'parameter_default_value_changed' => false,
22
		];
23 72
		$lengthA = count($parametersA);
24 72
		$lengthB = count($parametersB);
25
26
		// TODO([email protected]): This is only true if newer params do not have defaults
27 72
		if ($lengthA < $lengthB) {
28 9
			$changes['parameter_added'] = true;
29 63
		} elseif ($lengthA > $lengthB) {
30 8
			$changes['parameter_removed'] = true;
31
		}
32
33 72
		$iterations = min($lengthA, $lengthB);
34 72
		for ($i = 0; $i < $iterations; ++$i) {
35
			// Name checking
36 65
			if ($parametersA[$i]->name !== $parametersB[$i]->name) {
37 10
				$changes['parameter_renamed'] = true;
38
			}
39
40
			// Type checking
41 65
			if (Type::get($parametersA[$i]->type) !== Type::get($parametersB[$i]->type)) {
42
//				if ($paramsA[$i]->default !== null && $paramsB[$i]->default !== null) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
//					$changes['parameter_default_value_changed'] = true;
44 16
				if ($parametersA[$i]->type !== null) {
45 8
					$changes['parameter_typing_removed'] = true;
46
				}
47 16
				if ($parametersB[$i]->type !== null) {
48 8
					$changes['parameter_typing_added'] = true;
49
				}
50
			}
51
52
			// Default checking
53 65
			if ($parametersA[$i]->default === null && $parametersB[$i]->default === null) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
54
				// Do nothing
55 24
			} elseif ($parametersA[$i]->default !== null && $parametersB[$i]->default === null) {
56 8
				$changes['parameter_default_removed'] = true;
57 16
			} elseif ($parametersA[$i]->default === null && $parametersB[$i]->default !== null) {
58 8
				$changes['parameter_default_added'] = true;
59
			// TODO([email protected]): Not all nodes have a value property
60 8
			} elseif ( ! Node::isEqual($parametersA[$i]->default, $parametersB[$i]->default)) {
61 8
				$changes['parameter_default_value_changed'] = true;
62
			}
63
		}
64
65 72
		return $changes;
66
	}
67
}
68