1
|
|
|
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
2
|
|
|
/** |
3
|
|
|
* Function call finder script. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-analyzer |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Analyzer; |
9
|
|
|
|
10
|
|
|
use Composer\Script\Event; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This class holds the callback for the WordPress API function analyzer. |
14
|
|
|
*/ |
15
|
|
|
class CoreCalls { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* A static method to handle the Composer script call that |
19
|
|
|
* triggers a repository code scan for WordPress Core function |
20
|
|
|
* calls. |
21
|
|
|
* |
22
|
|
|
* @param Composer\Script\Event $event a script call event. |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public static function callback( Event $event ) { |
25
|
|
|
$arguments = $event->getArguments(); |
26
|
|
|
$scan_path = isset( $arguments[0] ) ? $arguments[0] : null; |
27
|
|
|
$core_path = isset( $arguments[1] ) ? $arguments[1] : null; |
28
|
|
|
$io = $event->getIO(); |
29
|
|
|
|
30
|
|
|
if ( |
31
|
|
|
is_null( $scan_path ) |
32
|
|
|
|| is_null( $core_path ) |
33
|
|
|
) { |
34
|
|
|
$io->writeError( 'Scan path and WordPress Core source paths are required for this script to work.' ); |
35
|
|
|
$io->writeError( 'Usage: composer run core-calls /path/to/plugin /path/to/wordpress/src' ); |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
try { |
40
|
|
|
$declarations = CoreDefinitions::get_declarations( $core_path ); |
41
|
|
|
|
42
|
|
|
$invocations = new Invocations(); |
43
|
|
|
$invocations->scan( $scan_path, array( 'vendor', 'vendor_prefixed' ) ); |
44
|
|
|
|
45
|
|
|
$dependencies = new Dependencies(); |
46
|
|
|
$dependencies->generate( $invocations, $declarations ); |
47
|
|
|
foreach ( $dependencies->get() as $dependency ) { |
48
|
|
|
|
49
|
|
|
$io->write( |
50
|
|
|
$dependency->invocation->display_name() . ', ' . |
51
|
|
|
$dependency->invocation->path . ', ' . |
52
|
|
|
$dependency->invocation->line |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
} catch ( Exception $e ) { |
|
|
|
|
57
|
|
|
$io->writeError( 'Exception caught' ); |
58
|
|
|
$io->writeError( $e->getMessage() ); |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.