Skip to content

Commit bda7a57

Browse files
committed
cs-fix
1 parent aa23279 commit bda7a57

9 files changed

+47
-28
lines changed

src/Psalm/Internal/Analyzer/Statements/EchoAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function analyze(
6666
TaintKind::INPUT_HTML
6767
| TaintKind::INPUT_HAS_QUOTES
6868
| TaintKind::USER_SECRET
69-
| TaintKind::SYSTEM_SECRET
69+
| TaintKind::SYSTEM_SECRET,
7070
);
7171

7272

src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public static function taintReturnType(
375375
$cased_method_id,
376376
$method_storage->signature_return_type_location ?: $method_storage->location,
377377
null,
378-
$method_storage->taint_source_types
378+
$method_storage->taint_source_types,
379379
);
380380

381381
$statements_analyzer->data_flow_graph->addSource($method_node);

src/Psalm/Internal/Analyzer/Statements/Expression/ExitAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function analyze(
7878
TaintKind::INPUT_HTML
7979
| TaintKind::INPUT_HAS_QUOTES
8080
| TaintKind::USER_SECRET
81-
| TaintKind::SYSTEM_SECRET
81+
| TaintKind::SYSTEM_SECRET,
8282
);
8383

8484
$statements_analyzer->data_flow_graph->addSink($echo_param_sink);

src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static function analyze(
122122
0,
123123
$arg_location,
124124
$arg_location,
125-
TaintKind::INPUT_INCLUDE
125+
TaintKind::INPUT_INCLUDE,
126126
);
127127

128128
$statements_analyzer->data_flow_graph->addSink($include_param_sink);

src/Psalm/Internal/Analyzer/Statements/Expression/PrintAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function analyze(
4848
TaintKind::INPUT_HTML
4949
| TaintKind::INPUT_HAS_QUOTES
5050
| TaintKind::USER_SECRET
51-
| TaintKind::SYSTEM_SECRET
51+
| TaintKind::SYSTEM_SECRET,
5252
);
5353

5454
$statements_analyzer->data_flow_graph->addSink($print_param_sink);

src/Psalm/Internal/Analyzer/StatementsAnalyzer.php

+24-10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Psalm\Internal\Analyzer\Statements\UnsetAnalyzer;
4040
use Psalm\Internal\Analyzer\Statements\UnusedAssignmentRemover;
4141
use Psalm\Internal\Codebase\DataFlowGraph;
42+
use Psalm\Internal\Codebase\TaintFlowGraph;
4243
use Psalm\Internal\Codebase\VariableUseGraph;
4344
use Psalm\Internal\DataFlow\DataFlowNode;
4445
use Psalm\Internal\FileManipulation\FileManipulationBuffer;
@@ -154,11 +155,29 @@ public function __construct(protected SourceAnalyzer $source, public NodeDataPro
154155
$this->file_analyzer = $source->getFileAnalyzer();
155156
$this->codebase = $source->getCodebase();
156157

157-
if (!$this->codebase->taint_flow_graph && $this->codebase->find_unused_variables) {
158+
if ($this->codebase->taint_flow_graph) {
159+
$this->initTaintFlowGraph(true);
160+
} elseif ($this->codebase->find_unused_variables) {
158161
$this->data_flow_graph = new VariableUseGraph();
159162
}
160163
}
161164

165+
private function initTaintFlowGraph(bool $enable): ?TaintFlowGraph
166+
{
167+
$old = $this->data_flow_graph;
168+
169+
if ($enable
170+
&& $this->codebase->taint_flow_graph
171+
&& $this->codebase->config->trackTaintsInPath($this->getFilePath())
172+
) {
173+
$this->data_flow_graph = $this->codebase->taint_flow_graph;
174+
} else {
175+
$this->data_flow_graph = null;
176+
}
177+
178+
return $old;
179+
}
180+
162181
/**
163182
* Checks an array of statements for validity
164183
*
@@ -177,16 +196,9 @@ public function analyze(
177196
// hoist functions to the top
178197
$this->hoistFunctions($stmts, $context);
179198

180-
$project_analyzer = $this->getFileAnalyzer()->project_analyzer;
181-
$codebase = $project_analyzer->getCodebase();
199+
$codebase = $this->codebase;
182200

183-
if ($this->codebase->taint_flow_graph) {
184-
if ($root_scope && $codebase->config->trackTaintsInPath($this->getFilePath())) {
185-
$this->data_flow_graph = $this->codebase->taint_flow_graph;
186-
} else {
187-
$this->data_flow_graph = null;
188-
}
189-
}
201+
$prev = $this->initTaintFlowGraph($root_scope);
190202

191203
if ($codebase->config->hoist_constants) {
192204
self::hoistConstants($this, $stmts, $context);
@@ -219,6 +231,8 @@ public function analyze(
219231
}
220232
}
221233

234+
$this->data_flow_graph = $prev;
235+
222236
return null;
223237
}
224238

src/Psalm/Internal/Codebase/TaintFlowGraph.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function connectSinksAndSources(Progress $progress): void
286286
$source->taints,
287287
$source->taintSource,
288288
$source->path_types,
289-
$specialized_calls
289+
$specialized_calls,
290290
);
291291

292292
$this->getChildNodes(
@@ -620,7 +620,7 @@ private function getChildNodes(
620620
$new_taints,
621621
$generated_source,
622622
$path_types,
623-
$generated_source->specialized_calls
623+
$generated_source->specialized_calls,
624624
);
625625

626626
$new_sources[$key] = $new_destination;

src/Psalm/Internal/Codebase/VariableUseGraph.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private function getChildNodes(
193193
null,
194194
0,
195195
null,
196-
$path_types
196+
$path_types,
197197
);
198198

199199
$new_child_nodes[$to_id] = $new_destination;

src/Psalm/Internal/DataFlow/DataFlowNode.php

+15-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Override;
88
use Psalm\CodeLocation;
9-
use Psalm\Storage\ImmutableNonCloneableTrait;
109
use Stringable;
1110

1211
use function strtolower;
@@ -30,7 +29,7 @@ public function __construct(
3029
/**
3130
* @var array<string, array<string, string>>
3231
*/
33-
public readonly array $specialized_calls = [],
32+
public readonly array $specialized_calls = [],
3433
) {
3534
}
3635

@@ -43,7 +42,7 @@ public static function make(
4342
string $label,
4443
?CodeLocation $code_location,
4544
?string $specialization_key = null,
46-
int $taints = 0
45+
int $taints = 0,
4746
): self {
4847
if ($specialization_key === null) {
4948
$unspecialized_id = null;
@@ -57,7 +56,7 @@ public static function make(
5756
$specialization_key,
5857
$label,
5958
$code_location,
60-
$taints
59+
$taints,
6160
);
6261
}
6362

@@ -91,11 +90,17 @@ public static function getForMethodArgument(
9190
public static function getForAssignment(
9291
string $var_id,
9392
CodeLocation $assignment_location,
94-
string $specialization_key = '',
93+
?string $specialization_key = null,
9594
): self {
96-
$specialization_key .= '-' . $assignment_location->file_name
97-
. ':' . $assignment_location->raw_file_start
98-
. '-' . $assignment_location->raw_file_end;
95+
if ($specialization_key === null) {
96+
$specialization_key = $assignment_location->file_name
97+
. ':' . $assignment_location->raw_file_start
98+
. '-' . $assignment_location->raw_file_end;
99+
} else {
100+
$specialization_key .= '-' . $assignment_location->file_name
101+
. ':' . $assignment_location->raw_file_start
102+
. '-' . $assignment_location->raw_file_end;
103+
}
99104

100105
return self::make($var_id, $var_id, $assignment_location, $specialization_key);
101106
}
@@ -105,7 +110,7 @@ public static function getForMethodReturn(
105110
string $cased_method_id,
106111
?CodeLocation $code_location,
107112
?CodeLocation $function_location = null,
108-
int $taints = 0
113+
int $taints = 0,
109114
): self {
110115
$specialization_key = null;
111116

@@ -153,7 +158,7 @@ public function setTaints(int $taints): self
153158
$taints,
154159
$this->taintSource,
155160
$this->path_types,
156-
$this->specialized_calls
161+
$this->specialized_calls,
157162
);
158163
}
159164

0 commit comments

Comments
 (0)