diff --git a/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php b/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php index 1f47aac9d..ca7103532 100644 --- a/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php +++ b/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php @@ -131,7 +131,7 @@ class FileManipulationBuffer return; } - $comment_end = strpos($file_contents, '*/', strlen($file_contents) - $bounds[1]); + $comment_end = strpos($file_contents, '*/', $bounds[1]); if ($comment_end === false) { return; @@ -145,7 +145,7 @@ class FileManipulationBuffer $var_type_comment_end = $bounds[1] - $comment_start; $var_start = strrpos($comment_text, '@var', $var_type_comment_start - strlen($comment_text)); - $var_end = strpos($comment_text, "\n", $var_type_comment_end - strlen($comment_text)); + $var_end = strpos($comment_text, "\n", $var_type_comment_end); if ($var_start && $var_end) { $var_start = strrpos($comment_text, "\n", $var_start - strlen($comment_text)) ?: $var_start; diff --git a/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php b/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php index dc6e35482..a44841d43 100644 --- a/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php +++ b/tests/FileManipulation/UnnecessaryVarAnnotationManipulationTest.php @@ -35,6 +35,30 @@ class UnnecessaryVarAnnotationManipulationTest extends FileManipulationTest ['UnnecessaryVarAnnotation'], true, ], + 'removeSingleLineVarAnnotationFlipped' => [ + ' [ '