-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathDollarDollarPlugin.php
More file actions
78 lines (71 loc) · 2.15 KB
/
DollarDollarPlugin.php
File metadata and controls
78 lines (71 loc) · 2.15 KB
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
76
77
78
<?php declare(strict_types=1);
use Phan\PluginV2;
use Phan\PluginV2\PostAnalyzeNodeCapability;
use Phan\PluginV2\PluginAwarePostAnalysisVisitor;
use ast\Node;
/**
* This plugin checks for occurrences of `$$x`,
* which may be a typo, or behave differently in php 5 vs 7, or be hard to analyze code.
*
* This file demonstrates plugins for Phan. Plugins hook into various events.
* DollarDollarPlugin hooks into one event:
*
* - getPostAnalyzeNodeVisitorClassName
* This method returns a visitor that is called on every AST node from every
* file being analyzed
*
* A plugin file must
*
* - Contain a class that inherits from \Phan\Plugin
*
* - End by returning an instance of that class.
*
* It is assumed without being checked that plugins aren't
* mangling state within the passed code base or context.
*
* Note: When adding new plugins,
* add them to the corresponding section of README.md
*/
class DollarDollarPlugin extends PluginV2 implements PostAnalyzeNodeCapability
{
/**
* @return string - name of PluginAwarePostAnalysisVisitor subclass
*/
public static function getPostAnalyzeNodeVisitorClassName() : string
{
return DollarDollarVisitor::class;
}
}
/**
* When __invoke on this class is called with a node, a method
* will be dispatched based on the `kind` of the given node.
*
* Visitors such as this are useful for defining lots of different
* checks on a node based on its kind.
*/
class DollarDollarVisitor extends PluginAwarePostAnalysisVisitor
{
// A plugin's visitors should not override visit() unless they need to.
/**
* @param Node $node
* A node to analyze
*
* @return void
* @override
*/
public function visitVar(Node $node)
{
if ($node->children['name'] instanceof Node) {
$this->emitPluginIssue(
$this->code_base,
$this->context,
'PhanPluginDollarDollar',
"$$ Variables are not allowed.",
[]
);
}
}
}
// Every plugin needs to return an instance of itself at the
// end of the file in which its defined.
return new DollarDollarPlugin();