mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #461 - allow multiple replacements at the same location
This commit is contained in:
parent
68b00ea49a
commit
dea1d58b2a
@ -7,6 +7,7 @@ use Psalm\Checker\FileChecker;
|
||||
use Psalm\Checker\MethodChecker;
|
||||
use Psalm\Checker\ProjectChecker;
|
||||
use Psalm\Checker\StatementsChecker;
|
||||
use Psalm\FileManipulation\FileManipulation;
|
||||
use Psalm\FileManipulation\FileManipulationBuffer;
|
||||
use Psalm\FileManipulation\FunctionDocblockManipulator;
|
||||
use Psalm\Issue\CircularReference;
|
||||
@ -913,9 +914,25 @@ class Codebase
|
||||
|
||||
$other_manipulations = FileManipulationBuffer::getForFile($file_path);
|
||||
|
||||
$file_manipulations = $new_return_type_manipulations + $other_manipulations;
|
||||
$file_manipulations = array_merge($new_return_type_manipulations, $other_manipulations);
|
||||
|
||||
krsort($file_manipulations);
|
||||
usort(
|
||||
$file_manipulations,
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
function (FileManipulation $a, FileManipulation $b) {
|
||||
if ($a->start === $b->start) {
|
||||
if ($b->end === $a->end) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $b->end > $a->end ? 1 : -1;
|
||||
}
|
||||
|
||||
return $b->start > $a->start ? 1 : -1;
|
||||
}
|
||||
);
|
||||
|
||||
$docblock_update_count = count($file_manipulations);
|
||||
|
||||
|
@ -30,13 +30,7 @@ class FileManipulationBuffer
|
||||
return [];
|
||||
}
|
||||
|
||||
$file_manipulations = [];
|
||||
|
||||
foreach (self::$file_manipulations[$file_path] as $file_manipulation) {
|
||||
$file_manipulations[$file_manipulation->start] = $file_manipulation;
|
||||
}
|
||||
|
||||
return $file_manipulations;
|
||||
return self::$file_manipulations[$file_path];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -671,6 +671,29 @@ class FileManipulationTest extends TestCase
|
||||
['PossiblyUndefinedVariable'],
|
||||
true,
|
||||
],
|
||||
'possiblyUndefinedVariable' => [
|
||||
'<?php
|
||||
if (rand(0, 1)) {
|
||||
$a = 1;
|
||||
$b = 2;
|
||||
}
|
||||
|
||||
echo $a;
|
||||
echo $b;',
|
||||
'<?php
|
||||
$b = null;
|
||||
$a = null;
|
||||
if (rand(0, 1)) {
|
||||
$a = 1;
|
||||
$b = 2;
|
||||
}
|
||||
|
||||
echo $a;
|
||||
echo $b;',
|
||||
'5.6',
|
||||
['PossiblyUndefinedVariable'],
|
||||
true,
|
||||
],
|
||||
'useUnqualifierPlugin' => [
|
||||
'<?php
|
||||
namespace A\B\C {
|
||||
|
Loading…
Reference in New Issue
Block a user