|
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
|
|
|
$moved = false; |
|
19
|
|
|
foreach ( $new_declarations->get() as $new_declaration ) { |
|
20
|
|
|
if ( $prev_declaration->match( $new_declaration ) ) { |
|
21
|
|
|
// echo "Comparing " . $prev_declaration->path . " to " . $new_declaration->path . "\n"; |
|
22
|
|
|
if ( $prev_declaration->path !== $new_declaration->path ) { |
|
23
|
|
|
$moved = true; |
|
24
|
|
|
} |
|
25
|
|
|
$matched = true; |
|
26
|
|
|
break; |
|
27
|
|
|
} elseif ( $prev_declaration->partial_match( $new_declaration ) ) { |
|
28
|
|
|
// TODO this is to catch things like function args changed, method the same |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if ( $matched && $moved ) { |
|
33
|
|
|
switch ( $prev_declaration->type() ) { |
|
34
|
|
|
case 'class': |
|
35
|
|
|
$this->add( new Differences\Class_Moved( $prev_declaration, $new_declaration ) ); |
|
|
|
|
|
|
36
|
|
|
break; |
|
37
|
|
|
case 'method': |
|
38
|
|
|
$this->add( new Differences\Class_Method_Moved( $prev_declaration, $new_declaration ) ); |
|
39
|
|
|
break; |
|
40
|
|
|
case 'property': |
|
41
|
|
|
$this->add( new Differences\Class_Property_Moved( $prev_declaration, $new_declaration ) ); |
|
42
|
|
|
break; |
|
43
|
|
|
case 'function': |
|
44
|
|
|
$this->add( new Differences\Function_Moved( $prev_declaration, $new_declaration ) ); |
|
45
|
|
|
break; |
|
46
|
|
|
default: |
|
47
|
|
|
echo 'Unknown moved type ' . $prev_declaration->type() . "\n"; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if ( ! $matched ) { |
|
52
|
|
|
switch ( $prev_declaration->type() ) { |
|
53
|
|
|
case 'class': |
|
54
|
|
|
$this->add( new Differences\Class_Missing( $prev_declaration ) ); |
|
55
|
|
|
break; |
|
56
|
|
|
case 'method': |
|
57
|
|
|
$this->add( new Differences\Class_Method_Missing( $prev_declaration ) ); |
|
58
|
|
|
break; |
|
59
|
|
|
case 'property': |
|
60
|
|
|
$this->add( new Differences\Class_Property_Missing( $prev_declaration ) ); |
|
61
|
|
|
break; |
|
62
|
|
|
case 'function': |
|
63
|
|
|
$this->add( new Differences\Function_Missing( $prev_declaration ) ); |
|
64
|
|
|
break; |
|
65
|
|
|
default: |
|
66
|
|
|
echo 'Unknown unmatched type ' . $prev_declaration->type() . "\n"; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$total += 1; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
echo "Total: $total\n"; |
|
74
|
|
|
echo 'Missing: ' . count( $this->get() ) . "\n"; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
It seems like you are relying on a variable being defined by an iteration: