Completed
Push — try/code-signature-diff ( 2d24ed...5d4d06 )
by
unknown
121:31 queued 111:30
created

check_file_compatibility()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 25
rs 9.52
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\NodeVisitor\NameResolver;
8
9
class Declaration_Differences {
10
	private $differences;
11
	private $parser;
12
13
	function __construct() {
14
		$this->parser      = ( new ParserFactory() )->create( ParserFactory::PREFER_PHP7 );
15
		$this->differences = array();
16
	}
17
18
	public function get() {
19
		return $this->differences;
20
	}
21
22
	public function add( $difference ) {
23
		$this->differences[] = $difference;
24
	}
25
26
	/**
27
	 * Scans the file for any invocations that depend on missing or different classes, methods, properties and functions
28
	 */
29
	public function check_file_compatibility( $file_path ) {
30
		$source = file_get_contents( $file_path );
31
		try {
32
			$ast = $this->parser->parse( $source );
33
		} 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...
34
			echo "Parse error: {$error->getMessage()}\n";
35
			return;
36
		}
37
38
		// $dumper = new NodeDumper;
39
		// echo $dumper->dump($ast) . "\n";
40
41
		// before parsing, make sure we try to resolve class names
42
		$traverser    = new NodeTraverser();
43
		$nameResolver = new NameResolver();
44
		$traverser->addVisitor( $nameResolver );
45
46
		// Resolve names
47
		$ast = $traverser->traverse( $ast );
48
49
		$traverser         = new NodeTraverser();
50
		$invocation_finder = new Invocations\Visitor( $this );
51
		$traverser->addVisitor( $invocation_finder );
52
		$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...
53
	}
54
}
55