Skip to content
Permalink
Browse files

Remove pure function calls when removing unused variables

  • Loading branch information...
muglug committed Aug 16, 2019
1 parent 5c1b4d5 commit 9c616aa5c66addfcd71f50432b1bcd56f4c5a3d7
@@ -631,20 +631,22 @@ public static function analyze(
} elseif ($function_id
&& (($function_storage && $function_storage->pure) || $callmap_function_pure === true)
&& $codebase->find_unused_variables
&& !$context->inside_assignment
&& !$context->inside_conditional
&& !$context->inside_call
&& !$context->inside_unset
) {
if (IssueBuffer::accepts(
new UnusedFunctionCall(
'The call to ' . $function_id . ' is not used',
new CodeLocation($statements_analyzer, $stmt->name),
$function_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
if (!$context->inside_assignment && !$context->inside_call) {
if (IssueBuffer::accepts(
new UnusedFunctionCall(
'The call to ' . $function_id . ' is not used',
new CodeLocation($statements_analyzer, $stmt->name),
$function_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
} else {
$stmt->pure = true;
}
}
}
@@ -38,6 +38,10 @@ private function checkNonTrivialExpr(PhpParser\Node\Expr $node)
|| $node instanceof PhpParser\Node\Expr\YieldFrom
|| $node instanceof PhpParser\Node\Expr\New_
) {
if ($node instanceof PhpParser\Node\Expr\FuncCall && isset($node->pure)) {
return false;
}
return true;
} else {
return false;
@@ -30,7 +30,7 @@ public function foo() : void {
true,
],
'removeUnusedVariableFunctionCall' => [
'removeUnusedVariableAndFunctionCall' => [
'<?php
class A {
public function foo() : void {
@@ -42,7 +42,6 @@ public function foo() : void {
'<?php
class A {
public function foo() : void {
substr("wonderful", 2);
$b = "hello";
echo $b;
}
@@ -87,9 +86,7 @@ public function foo() : void {
'<?php
class A {
public function foo() : void {
substr("hello world", 4);
$b = "b";
file_get_contents("foo.php");
echo $b;
}
}',
@@ -408,7 +405,6 @@ function foo() : void {
function foo() : void {
$a = 5;
$b = 6;
intval("4");
echo "foo";
}',
'7.1',

0 comments on commit 9c616aa

Please sign in to comment.
You can’t perform that action at this time.