Skip to content

Commit 79ca8ce

Browse files
authored
Merge pull request #11629 from danog/improve_getIssueTrace
Improve performance of getIssueTrace
2 parents ec7d579 + ccf7db7 commit 79ca8ce

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

psalm-baseline.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.x-dev@2b0ff73c8bed091af231a0a80ac109126c92083a">
2+
<files psalm-version="6.x-dev@bbd217fc98c0daa0a13aea2a7f119d03ba3fc9a0">
33
<file src="examples/TemplateChecker.php">
44
<PossiblyUndefinedIntArrayOffset>
55
<code><![CDATA[$comment_block->tags['variablesfrom'][0]]]></code>
@@ -1612,8 +1612,11 @@
16121612
<code><![CDATA[$path->escaped_taints]]></code>
16131613
<code><![CDATA[$path->unescaped_taints]]></code>
16141614
<code><![CDATA[$source->specialization_key]]></code>
1615-
<code><![CDATA[end($source->path_types)]]></code>
1615+
<code><![CDATA[end($path_types)]]></code>
16161616
</RiskyTruthyFalsyComparison>
1617+
<UnnecessaryVarAnnotation>
1618+
<code><![CDATA[DataFlowNode]]></code>
1619+
</UnnecessaryVarAnnotation>
16171620
</file>
16181621
<file src="src/Psalm/Internal/Composer.php">
16191622
<RiskyTruthyFalsyComparison>

src/Psalm/Internal/Codebase/TaintFlowGraph.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use function array_intersect;
3939
use function array_merge;
4040
use function array_unique;
41+
use function array_unshift;
4142
use function count;
4243
use function end;
4344
use function implode;
@@ -183,23 +184,23 @@ public function getSuccessorPath(DataFlowNode $sink): string
183184
*/
184185
public function getIssueTrace(DataFlowNode $source): array
185186
{
186-
$previous_source = $source->previous;
187-
188-
$node = [
189-
'location' => $source->code_location,
190-
'label' => $source->label,
191-
'entry_path_type' => end($source->path_types) ?: '',
192-
];
193-
194-
if ($previous_source) {
187+
$out = [];
188+
do {
189+
/** @var DataFlowNode $source */
190+
$previous_source = $source->previous;
195191
if ($previous_source === $source) {
196-
return [];
192+
break;
197193
}
198-
199-
return [...$this->getIssueTrace($previous_source), $node];
200-
}
201-
202-
return [$node];
194+
$path_types = $source->path_types;
195+
array_unshift($out, [
196+
'location' => $source->code_location,
197+
'label' => $source->label,
198+
'entry_path_type' => end($path_types) ?: '',
199+
]);
200+
$source = $previous_source;
201+
} while ($previous_source);
202+
203+
return $out;
203204
}
204205

205206
public function connectSinksAndSources(): void

0 commit comments

Comments
 (0)