Skip to content

Commit

Permalink
Fix #5517 - don’t let a variable’s by-refness be overwritten by a @var
Browse files Browse the repository at this point in the history
…docblock
  • Loading branch information
muglug committed Apr 25, 2021
1 parent 7b7354e commit 67c5dc3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public static function analyze(
$comment_type_location,
$not_ignored_docblock_var_ids
);

if ($var_id === $var_comment->var_id && $assign_value_type && $comment_type) {
$comment_type->by_ref = $assign_value_type->by_ref;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/UnusedVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,16 @@ function foo(object $a, string $k) : string {
return $sortA;
}'
],
'varDocblockVariableIsUsedByRef' => [
'<?php
function foo(array $arr) : string {
/** @var string $val */
foreach ($arr as &$val) {
$val = urlencode($val);
}
return implode("/", $arr);
}'
],
];
}

Expand Down

0 comments on commit 67c5dc3

Please sign in to comment.