Skip to content

Commit

Permalink
Merge pull request #9400 from edsrzf/psalter-possibly-undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 25, 2023
2 parents 99a69b4 + f7eaa5d commit 6ac2b8d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Expand Up @@ -321,11 +321,9 @@ public static function analyze(
(bool) $statements_analyzer->getBranchPoint($var_name),
);
} else {
if ($codebase->alter_code) {
if (!isset($project_analyzer->getIssuesToFix()['PossiblyUndefinedVariable'])) {
return true;
}

if ($codebase->alter_code
&& isset($project_analyzer->getIssuesToFix()['PossiblyUndefinedVariable'])
) {
$branch_point = $statements_analyzer->getBranchPoint($var_name);

if ($branch_point) {
Expand Down
21 changes: 21 additions & 0 deletions tests/FileManipulation/UnusedVariableManipulationTest.php
Expand Up @@ -27,6 +27,27 @@ public function foo() : void {
'issues_to_fix' => ['UnusedVariable'],
'safe_types' => true,
],
'dontRemovePossiblyUndefined' => [
'input' => '<?php
function foo(bool $b): void {
if ($b) {
$v = "hi";
}
echo $v;
}',
'output' => '<?php
function foo(bool $b): void {
if ($b) {
$v = "hi";
}
echo $v;
}',
'php_version' => '7.1',
'issues_to_fix' => ['UnusedVariable'],
'safe_types' => true,
],
'removeUnusedVariableFromTry' => [
'input' => '<?php
class A {
Expand Down

0 comments on commit 6ac2b8d

Please sign in to comment.