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

ClassAnalyzer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 86.21%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 6
c 5
b 0
f 1
lcom 0
cbo 6
dl 54
loc 54
ccs 25
cts 29
cp 0.8621
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B analyze() 50 50 6

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\Analyzer;
4
5
use PHPSemVerChecker\Operation\ClassAdded;
6
use PHPSemVerChecker\Operation\ClassRemoved;
7
use PHPSemVerChecker\Registry\Registry;
8
use PHPSemVerChecker\Report\Report;
9
10 View Code Duplication
class ClassAnalyzer {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
11
	protected $context = 'class';
12
13 4
	public function analyze(Registry $registryBefore, Registry $registryAfter)
14
	{
15 4
		$report = new Report();
16
17 4
		$keysBefore = array_keys($registryBefore->data['class']);
18 4
		$keysAfter = array_keys($registryAfter->data['class']);
19 4
		$added = array_diff($keysAfter, $keysBefore);
20 4
		$removed = array_diff($keysBefore, $keysAfter);
21 4
		$toVerify = array_intersect($keysBefore, $keysAfter);
22
23 4
		foreach ($removed as $key) {
24 1
			$fileBefore = $registryBefore->mapping['class'][$key];
25 1
			$classBefore = $registryBefore->data['class'][$key];
26
27 1
			$data = new ClassRemoved($fileBefore, $classBefore);
28 1
			$report->addClass($data);
29
		}
30
31 4
		foreach ($toVerify as $key) {
32 1
			$fileBefore = $registryBefore->mapping['class'][$key];
33
			/** @var \PhpParser\Node\Stmt\Class_ $classBefore */
34 1
			$classBefore = $registryBefore->data['class'][$key];
35 1
			$fileAfter = $registryAfter->mapping['class'][$key];
36
			/** @var \PhpParser\Node\Stmt\Class_ $classBefore */
37 1
			$classAfter = $registryAfter->data['class'][$key];
38
39
			// Leave non-strict comparison here
40 1
			if ($classBefore != $classAfter) {
41
				$analyzers = [
42
					new ClassMethodAnalyzer('class', $fileBefore, $fileAfter),
43
					new PropertyAnalyzer('class', $fileBefore, $fileAfter),
44
				];
45
46
				foreach ($analyzers as $analyzer) {
47
					$internalReport = $analyzer->analyze($classBefore, $classAfter);
48 1
					$report->merge($internalReport);
49
				}
50
			}
51
		}
52
53 4
		foreach ($added as $key) {
54 1
			$fileAfter = $registryAfter->mapping['class'][$key];
55 1
			$classAfter = $registryAfter->data['class'][$key];
56
57 1
			$data = new ClassAdded($fileAfter, $classAfter);
58 1
			$report->addClass($data);
59
		}
60
61 4
		return $report;
62
	}
63
}
64