1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 22:01:48 +01:00

Merge pull request #9400 from edsrzf/psalter-possibly-undefined

This commit is contained in:
Bruce Weirdan 2023-02-25 04:26:56 -04:00 committed by GitHub
commit 6ac2b8d5a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -321,11 +321,9 @@ class VariableFetchAnalyzer
(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) {

View File

@ -27,6 +27,27 @@ class UnusedVariableManipulationTest extends FileManipulationTestCase
'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 {