Completed
Pull Request — master (#82)
by Graham
15:21 queued 09:41
created

Signature::isSameVariables()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 5
Ratio 35.71 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 14
ccs 7
cts 8
cp 0.875
rs 9.2
cc 4
eloc 8
nc 4
nop 2
crap 4.0312
1
<?php
2
3
namespace PHPSemVerChecker\Comparator;
4
5
class Signature {
6
	/**
7
	 * @param array $paramsA
8
	 * @param array $paramsB
9
	 * @return bool
10
	 */
11 15
	public static function isSameTypehints(array $paramsA, array $paramsB)
12
	{
13 15
		$iterations = min(count($paramsA), count($paramsB));
14 15 View Code Duplication
		for ($i = 0; $i < $iterations; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
			// TODO: Allow for contravariance <[email protected]>
16 12
			if ( ! Type::isSame($paramsA[$i]->type, $paramsB[$i]->type)) {
17 8
				return false;
18
			}
19
		}
20
		// Only one of these will return its remaining values, the other returning an empty array
21 7
		$toCheck = array_slice($paramsA, $iterations) + array_slice($paramsB, $iterations);
22
		// If any additional argument does not have a default value, the signature has changed
23 7
		foreach ($toCheck as $param) {
24
			if ($param->default === null) {
25
				return false;
26
			}
27
		}
28 7
		return true;
29
	}
30
31
	/**
32
	 * @param array $paramsA
33
	 * @param array $paramsB
34
	 * @return bool
35
	 */
36 7
	public static function isSameVariables(array $paramsA, array $paramsB)
37
	{
38 7
		if (count($paramsA) !== count($paramsB)) {
39
			return false;
40
		}
41
42 7
		$iterations = min(count($paramsA), count($paramsB));
43 7 View Code Duplication
		for ($i = 0; $i < $iterations; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44 4
			if ($paramsA[$i]->name != $paramsB[$i]->name) {
45 4
				return false;
46
			}
47
		}
48 3
		return true;
49
	}
50
}
51