@@ -150,32 +150,19 @@ final class StatementsAnalyzer extends SourceAnalyzer
150
150
*/
151
151
public array $ foreach_var_locations = [];
152
152
153
- public function __construct (protected SourceAnalyzer $ source , public NodeDataProvider $ node_data )
153
+ public function __construct (protected SourceAnalyzer $ source , public NodeDataProvider $ node_data, private readonly bool $ root_scope )
154
154
{
155
155
$ this ->file_analyzer = $ source ->getFileAnalyzer ();
156
156
$ this ->codebase = $ source ->getCodebase ();
157
157
158
- if ($ this ->codebase ->taint_flow_graph ) {
159
- $ this ->initTaintFlowGraph (true );
160
- } elseif ($ this ->codebase ->find_unused_variables ) {
161
- $ this ->data_flow_graph = new VariableUseGraph ();
162
- }
163
- }
164
-
165
- private function initTaintFlowGraph (bool $ enable ): ?TaintFlowGraph
166
- {
167
- $ old = $ this ->data_flow_graph ;
168
-
169
- if ($ enable
170
- && $ this ->codebase ->taint_flow_graph
158
+ if ($ this ->codebase ->taint_flow_graph
159
+ && $ root_scope
171
160
&& $ this ->codebase ->config ->trackTaintsInPath ($ this ->getFilePath ())
172
161
) {
173
162
$ this ->data_flow_graph = $ this ->codebase ->taint_flow_graph ;
174
- } else {
175
- $ this ->data_flow_graph = null ;
163
+ } elseif ( $ this -> codebase -> find_unused_variables ) {
164
+ $ this ->data_flow_graph = new VariableUseGraph () ;
176
165
}
177
-
178
- return $ old ;
179
166
}
180
167
181
168
/**
@@ -188,7 +175,6 @@ public function analyze(
188
175
array $ stmts ,
189
176
Context $ context ,
190
177
?Context $ global_context = null ,
191
- bool $ root_scope = false ,
192
178
): ?bool {
193
179
if (!$ stmts ) {
194
180
return null ;
@@ -198,8 +184,6 @@ public function analyze(
198
184
199
185
$ codebase = $ this ->codebase ;
200
186
201
- $ prev = $ this ->initTaintFlowGraph ($ root_scope );
202
-
203
187
if ($ codebase ->config ->hoist_constants ) {
204
188
self ::hoistConstants ($ this , $ stmts , $ context );
205
189
}
@@ -210,7 +194,7 @@ public function analyze(
210
194
}
211
195
}
212
196
213
- if ($ root_scope
197
+ if ($ this -> root_scope
214
198
&& !$ context ->collect_initializations
215
199
&& !$ context ->collect_mutations
216
200
&& $ codebase ->find_unused_variables
@@ -219,7 +203,7 @@ public function analyze(
219
203
$ this ->checkUnreferencedVars ($ stmts , $ context );
220
204
}
221
205
222
- if ($ codebase ->alter_code && $ root_scope && $ this ->vars_to_initialize ) {
206
+ if ($ codebase ->alter_code && $ this -> root_scope && $ this ->vars_to_initialize ) {
223
207
$ file_contents = $ codebase ->getFileContents ($ this ->getFilePath ());
224
208
225
209
foreach ($ this ->vars_to_initialize as $ var_id => $ branch_point ) {
@@ -231,8 +215,6 @@ public function analyze(
231
215
}
232
216
}
233
217
234
- $ this ->data_flow_graph = $ prev ;
235
-
236
218
return null ;
237
219
}
238
220
0 commit comments