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

Signature   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 23.91 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 0
cbo 1
dl 11
loc 46
ccs 15
cts 18
cp 0.8333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B isSameTypehints() 6 19 5
A isSameVariables() 5 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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