Completed
Push — try/code-signature-diff ( 9196c0...4ac422 )
by
unknown
183:18 queued 174:43
created

Declarations::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
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 );
0 ignored issues
show
Unused Code introduced by
$num is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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
}