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

I think I understand strpos/strrpos a little better now

This commit is contained in:
Brown 2019-09-26 15:31:56 -04:00
parent 4832aa6075
commit 73eb71bada
2 changed files with 26 additions and 2 deletions

View File

@ -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;

View File

@ -35,6 +35,30 @@ class UnnecessaryVarAnnotationManipulationTest extends FileManipulationTest
['UnnecessaryVarAnnotation'],
true,
],
'removeSingleLineVarAnnotationFlipped' => [
'<?php
function foo() : string {
return "hello";
}
/** @var "a"|"b" */
$b = foo();
/** @var string */
$a = foo();',
'<?php
function foo() : string {
return "hello";
}
/** @var "a"|"b" */
$b = foo();
$a = foo();',
'5.6',
['UnnecessaryVarAnnotation'],
true,
],
'removeSingleLineVarAnnotationAndType' => [
'<?php
function foo() : string {