|
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 ) { |
|
|
|
|
|
|
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 ); |
|
|
|
|
|
|
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
|
|
|
|
Scrutinizer analyzes your
composer.json/composer.lockfile 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.