Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set inside_call for eval expressions #9519

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,7 +26,10 @@ public static function analyze(
PhpParser\Node\Expr\Eval_ $stmt,
Context $context
): void {
$was_inside_call = $context->inside_call;
$context->inside_call = true;
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context);
$context->inside_call = $was_inside_call;

$codebase = $statements_analyzer->getCodebase();

Expand Down
4 changes: 4 additions & 0 deletions tests/UnusedCodeTest.php
Expand Up @@ -709,6 +709,10 @@ function takesMixed($i) : int {
return $i;
}',
],
'usedFunctionCallInEval' => [
'code' => '<?php
eval(str_repeat("a", 10));',
],
'usedFunctionCallInsideSwitchWithTernary' => [
'code' => '<?php
function getArg(string $method) : void {
Expand Down
7 changes: 7 additions & 0 deletions tests/UnusedVariableTest.php
Expand Up @@ -115,6 +115,13 @@ public function providerValidCodeParse(): array

unset($arr[$a]);',
],
'eval' => [
'code' => '<?php
if (rand()) {
$v = "";
eval($v);
}',
],
'usedVariables' => [
'code' => '<?php
/** @return string */
Expand Down