|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Automattic\Jetpack\Analyzer; |
|
4
|
|
|
|
|
5
|
|
|
class Declarations extends PersistentList { |
|
6
|
|
|
|
|
7
|
|
|
public function load( $file_path ) { |
|
8
|
|
|
$row = 1; |
|
9
|
|
|
if ( ( $handle = fopen( $file_path , "r" ) ) !== FALSE ) { |
|
10
|
|
|
while ( ( $data = fgetcsv( $handle, 1000, "," ) ) !== FALSE ) { |
|
11
|
|
|
$num = count( $data ); |
|
|
|
|
|
|
12
|
|
|
list( $type, $file, $line, $class_name, $name, $static, $params_json ) = $data; |
|
13
|
|
|
|
|
14
|
|
|
switch( $type ) { |
|
15
|
|
|
case 'class': |
|
16
|
|
|
$this->add( new Declarations\Class_( $file, $line, $class_name ) ); |
|
17
|
|
|
break; |
|
18
|
|
|
|
|
19
|
|
|
case 'property': |
|
20
|
|
|
$this->add( new Declarations\Class_Property( $file, $line, $class_name, $name, $static ) ); |
|
21
|
|
|
break; |
|
22
|
|
|
|
|
23
|
|
View Code Duplication |
case 'method': |
|
24
|
|
|
$params = json_decode( $params_json, TRUE ); |
|
25
|
|
|
$declaration = new Declarations\Class_Method( $file, $line, $class_name, $name, $static ); |
|
26
|
|
|
if ( is_array( $params ) ) { |
|
27
|
|
|
foreach( $params as $param ) { |
|
28
|
|
|
$declaration->add_param( $param->name, $param->default, $param->type, $param->byRef, $param->variadic ); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->add( $declaration ); |
|
33
|
|
|
|
|
34
|
|
|
break; |
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
case 'function': |
|
37
|
|
|
$params = json_decode( $params_json, TRUE ); |
|
38
|
|
|
$declaration = new Declarations\Function_( $file, $line, $name ); |
|
39
|
|
|
if ( is_array( $params ) ) { |
|
40
|
|
|
foreach( $params as $param ) { |
|
41
|
|
|
$declaration->add_param( $param->name, $param->default, $param->type, $param->byRef, $param->variadic ); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->add( $declaration ); |
|
46
|
|
|
|
|
47
|
|
|
break; |
|
48
|
|
|
} |
|
49
|
|
|
$row++; |
|
50
|
|
|
} |
|
51
|
|
|
fclose( $handle ); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function find_differences( $prev_declarations ) { |
|
56
|
|
|
$differences = new Differences(); |
|
57
|
|
|
$total = 0; |
|
58
|
|
|
// for each declaration, see if it exists in the current analyzer's declarations |
|
59
|
|
|
// if not, add it to the list of differences - either as missing or different |
|
60
|
|
|
foreach( $prev_declarations->get() as $prev_declaration ) { |
|
61
|
|
|
$matched = false; |
|
62
|
|
|
foreach( $this->get() as $declaration ) { |
|
63
|
|
|
if ( $prev_declaration->match( $declaration ) ) { |
|
64
|
|
|
$matched = true; |
|
65
|
|
|
break; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
if ( ! $matched ) { |
|
69
|
|
|
$differences->add( new Differences\Missing( $prev_declaration ) ); |
|
70
|
|
|
} |
|
71
|
|
|
$total += 1; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
echo "Total: $total\n"; |
|
75
|
|
|
echo "Missing: " . count( $differences->get() ) . "\n"; |
|
76
|
|
|
return $differences; |
|
77
|
|
|
} |
|
78
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.