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

Differences::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
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
	/**
13
	 * Scans the file for any invocations that depend on missing or different classes, methods, properties and functions
14
	 */
15
	public function check_file_compatibility( $file_path ) {
16
		$source = file_get_contents( $file_path );
17
		$parser = ( new ParserFactory() )->create( ParserFactory::PREFER_PHP7 );
18
		try {
19
			$ast    = $parser->parse( $source );
20
		} catch ( Error $error ) {
0 ignored issues
show
Bug introduced by
The class Automattic\Jetpack\Analyzer\Error does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
21
			echo "Parse error: {$error->getMessage()}\n";
22
			return;
23
		}
24
25
		// $dumper = new NodeDumper;
26
		// echo $dumper->dump($ast) . "\n";
27
28
		// before parsing, make sure we try to resolve class names
29
		$traverser    = new NodeTraverser();
30
		$nameResolver = new NameResolver();
31
		$traverser->addVisitor( $nameResolver );
32
33
		// Resolve names
34
		$ast = $traverser->traverse( $ast );
35
36
		$traverser         = new NodeTraverser();
37
		$invocations       = new Invocations();
38
		$invocation_finder = new Invocations\Visitor( $file_path, $invocations );
39
		$traverser->addVisitor( $invocation_finder );
40
		$ast = $traverser->traverse( $ast );
0 ignored issues
show
Unused Code introduced by
$ast 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...
41
42
		print_r($invocations);
43
		$invocations->print();
44
		// return $invocations;
45
46
		// $dumper = new NodeDumper;
47
		// echo $dumper->dump($ast) . "\n";
48
49
		// TODO: return a list of warnings and errors
50
	}
51
}
52