mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6376 from orklah/use-variable-in-backtick
This commit is contained in:
commit
624246b996
@ -517,6 +517,9 @@ return [
|
||||
'phpparser\\node\\matcharm' => [
|
||||
'conds' => 'null|non-empty-list<PhpParser\Node\Expr>',
|
||||
],
|
||||
'phpparser\\node\\expr\\shellexec' => [
|
||||
'parts' => 'list<PhpParser\Node>',
|
||||
],
|
||||
'rdkafka\\message' => [
|
||||
'err' => 'int',
|
||||
'topic_name' => 'string',
|
||||
|
@ -11,6 +11,8 @@ use Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer;
|
||||
use Psalm\Internal\Analyzer\Statements\Expression\Call\NewAnalyzer;
|
||||
use Psalm\Internal\Analyzer\Statements\Expression\Call\StaticCallAnalyzer;
|
||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||
use Psalm\Internal\Codebase\VariableUseGraph;
|
||||
use Psalm\Internal\DataFlow\DataFlowNode;
|
||||
use Psalm\Internal\FileManipulation\FileManipulationBuffer;
|
||||
use Psalm\Issue\ForbiddenCode;
|
||||
use Psalm\Issue\UnrecognizedExpression;
|
||||
@ -340,6 +342,29 @@ class ExpressionAnalyzer
|
||||
}
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Expr\ShellExec) {
|
||||
if ($statements_analyzer->data_flow_graph instanceof VariableUseGraph) {
|
||||
foreach ($stmt->parts as $part) {
|
||||
if ($part instanceof PhpParser\Node\Expr\Variable) {
|
||||
if (self::analyze($statements_analyzer, $part, $context) === false) {
|
||||
break;
|
||||
}
|
||||
|
||||
$expr_type = $statements_analyzer->node_data->getType($part);
|
||||
if ($expr_type === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($expr_type->parent_nodes as $parent_node) {
|
||||
$statements_analyzer->data_flow_graph->addPath(
|
||||
$parent_node,
|
||||
new DataFlowNode('variable-use', 'variable use', null),
|
||||
'variable-use'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new ForbiddenCode(
|
||||
'Use of shell_exec',
|
||||
|
@ -1049,6 +1049,13 @@ class UnusedCodeTest extends TestCase
|
||||
}
|
||||
',
|
||||
],
|
||||
'variableUsedInBacktick' => [
|
||||
'<?php
|
||||
$used = "echo";
|
||||
/** @psalm-suppress ForbiddenCode */
|
||||
`$used`;
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user