Completed
Push — try/code-signature-diff ( 76da74...88bced )
by
unknown
261:36 queued 253:34
created

Differences::check_file_compatibility()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 49
rs 9.1127
c 0
b 0
f 0
1
<?php
2
3
namespace Automattic\Jetpack\Analyzer;
4
5
use PhpParser\ParserFactory;
6
use PhpParser\NodeTraverser;
7
use PhpParser\NodeDumper;
8
use PhpParser\NodeVisitor\NameResolver;
9
10
class Differences extends PersistentList {
11
12
	public function find( $new_declarations, $prev_declarations ) {
13
		$total = 0;
14
		// for each declaration, see if it exists in the current analyzer's declarations
15
		// if not, add it to the list of differences - either as missing or different
16
		foreach( $prev_declarations->get() as $prev_declaration ) {
17
			$matched = false;
18
			foreach( $new_declarations->get() as $new_declaration ) {
19
				if ( $prev_declaration->match( $new_declaration ) ) {
20
					$matched = true;
21
					break;
22
				}
23
			}
24
			if ( ! $matched ) {
25
				switch( $prev_declaration->type() ) {
26
					case 'class':
27
						$this->add( new Differences\Class_Missing( $prev_declaration ) );
28
						break;
29
					case 'method':
30
						$this->add( new Differences\Class_Method_Missing( $prev_declaration ) );
31
						break;
32
					default:
33
						echo "Unknown unmatched type " . $prev_declaration->type() . "\n";
34
				}
35
			}
36
			$total += 1;
37
		}
38
39
		echo "Total: $total\n";
40
		echo "Missing: " . count( $this->get() ) . "\n";
41
	}
42
}
43