forked from psalm/psalm-plugin-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
75 lines (62 loc) · 1.79 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace PsalmWordpress;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use Psalm\Codebase;
use Psalm\Context;
use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;
use Psalm\StatementsSource;
use SimpleXMLElement;
class Plugin implements PluginEntryPointInterface {
static $last_statement = null;
public function __invoke( RegistrationInterface $psalm, ?SimpleXMLElement $config = null ) {
$psalm->registerHooksFromClass( static::class );
array_map( [ $psalm, 'addStubFile' ], $this->getStubFiles() );
// Psalm allows arbitrary content to be stored under you plugin entry in
// its config file, psalm.xml, so you plugin users can put some configuration
// values there. They will be provided to your plugin entry point in $config
// parameter, as a SimpleXmlElement object. If there's no configuration present,
// null will be passed instead.
}
/**
* @return string[]
*/
private function getStubFiles(): array {
return [
__DIR__ . '/stubs/wordpress.php',
__DIR__ . '/stubs/overrides.php',
];
}
public static function afterEveryFunctionCallAnalysis(
FuncCall $expr,
string $function_id,
Context $context,
StatementsSource $statements_source,
Codebase $codebase
): void {
$functions = [
'apply_filters',
'apply_filters_ref_array',
'apply_filters_deprecated',
'do_action',
'do_action_ref_array',
'do_action_deprecated',
];
if ( ! in_array( $function_id, $functions, true ) ) {
return;
}
if ( ! $expr->args[0]->value instanceof String_ ) {
return;
}
$name = $expr->args[0]->value->value;
var_dump( $name );
if ( $name === 'get_attached_file' ) {
return;
}
var_dump( $expr );
var_dump( $expr->getDocComment() );
//var_dump( static::$last_statement );
exit;
}
}