|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* LanguageFeatureAnalyser.php |
|
4
|
|
|
* |
|
5
|
|
|
* MIT LICENSE |
|
6
|
|
|
* |
|
7
|
|
|
* LICENSE: This source file is subject to the MIT license. |
|
8
|
|
|
* A copy of the licenses text was distributed alongside this |
|
9
|
|
|
* file (usually the repository or package root). The text can also |
|
10
|
|
|
* be obtained through one of the following sources: |
|
11
|
|
|
* * http://opensource.org/licenses/MIT |
|
12
|
|
|
* * https://github.com/suralc/pvra/blob/master/LICENSE |
|
13
|
|
|
* |
|
14
|
|
|
* @author suralc <[email protected]> |
|
15
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
16
|
|
|
*/ |
|
17
|
|
|
namespace Pvra\Analysers; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
use PhpParser\Node; |
|
21
|
|
|
use PhpParser\NodeVisitorAbstract; |
|
22
|
|
|
use Pvra\Analyser; |
|
23
|
|
|
use Pvra\AnalyserAwareInterface; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class LanguageFeatureAnalyser |
|
27
|
|
|
* |
|
28
|
|
|
* @package Pvra\PhpParser\Analysers |
|
29
|
|
|
*/ |
|
30
|
|
|
abstract class LanguageFeatureAnalyser extends NodeVisitorAbstract implements AnalyserAwareInterface |
|
31
|
|
|
{ |
|
32
|
|
|
const MODE_ADDITION = 0b0001, |
|
33
|
|
|
MODE_DEPRECATION = 0b0010, |
|
34
|
|
|
MODE_REMOVAL = 0b0100, |
|
35
|
|
|
MODE_ALL = 0b0111; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Bitmap of operations to run. |
|
39
|
|
|
* |
|
40
|
|
|
* @var int |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $mode; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The `Analyser` representing the currently running operation. |
|
46
|
|
|
* |
|
47
|
|
|
* @var Analyser |
|
48
|
|
|
*/ |
|
49
|
|
|
private $requirementAnalyser; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var array |
|
53
|
|
|
*/ |
|
54
|
|
|
private $options; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Create an instance of the child Analyser |
|
58
|
|
|
* |
|
59
|
|
|
* It is optional to set the related analyser during instance creation. |
|
60
|
|
|
* When using this class in the context of an `Analyser` it will always be ensured |
|
61
|
|
|
* that this `Analyser` will be known to the instance before any node is traversed. |
|
62
|
|
|
* |
|
63
|
|
|
* @param array $options |
|
64
|
|
|
* @param \Pvra\Analyser $analyser |
|
65
|
|
|
* @see setOwningAnalyser() Set the owning analyser |
|
66
|
|
|
*/ |
|
67
|
168 |
|
public function __construct(array $options = [], Analyser $analyser = null) |
|
68
|
|
|
{ |
|
69
|
168 |
|
$this->options = $options; |
|
70
|
168 |
|
$this->mode = $this->getOption('mode', self::MODE_ALL); |
|
71
|
168 |
|
if ($analyser !== null) { |
|
72
|
26 |
|
$this->setOwningAnalyser($analyser); |
|
73
|
13 |
|
} |
|
74
|
168 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @inheritdoc |
|
78
|
|
|
*/ |
|
79
|
160 |
|
public function setOwningAnalyser(Analyser $requirementAnalyser) |
|
80
|
|
|
{ |
|
81
|
160 |
|
$this->requirementAnalyser = $requirementAnalyser; |
|
82
|
|
|
|
|
83
|
160 |
|
return $this; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @inheritdoc |
|
88
|
|
|
*/ |
|
89
|
120 |
|
public function getOwningAnalyser() |
|
90
|
|
|
{ |
|
91
|
120 |
|
return $this->requirementAnalyser; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get the instance of the currently used `Pvra\AnalysisResult`. |
|
96
|
|
|
* |
|
97
|
|
|
* @return \Pvra\AnalysisResult |
|
98
|
|
|
* @see Analyser::getResult() Method used to retrieve the result |
|
99
|
|
|
*/ |
|
100
|
118 |
|
protected function getResult() |
|
101
|
|
|
{ |
|
102
|
118 |
|
return $this->getOwningAnalyser()->getResult(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param string|int $name |
|
107
|
|
|
* @param mixed $default |
|
108
|
|
|
* @return mixed |
|
109
|
|
|
*/ |
|
110
|
168 |
|
protected function getOption($name, $default = null) |
|
111
|
|
|
{ |
|
112
|
168 |
|
return isset($this->options[ $name ]) ? $this->options[ $name ] : $default; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Called when entering a source node |
|
117
|
|
|
* |
|
118
|
|
|
* This method is called when a source node is entered. Contained logic determines the presence of |
|
119
|
|
|
* specific syntactical features. |
|
120
|
|
|
* |
|
121
|
|
|
* @param \PhpParser\Node $node The node to parse. |
|
122
|
|
|
* @return null|Node The nodes should not be modified as other walkers might depend on it. |
|
123
|
|
|
* @see getResult() ResultInstance |
|
124
|
|
|
* @see AnalysisResult::addRequirement() Add new requirement |
|
125
|
|
|
* @see AnalysisResult::addArbitraryRequirement() Add new arbitrary requirement |
|
126
|
|
|
* @codeCoverageIgnore |
|
127
|
|
|
*/ |
|
128
|
|
|
public function enterNode(Node $node) |
|
129
|
|
|
{ |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|