Phpstorm extract method bug.
I have some code inside a loop like
foreach ($buckets as $platform) {
foreach ($platform['all_app']['buckets'] as $app) {
$game = CacheManagerUtil::getGame($app['key']);
$dayBuckets = $app['day']['buckets'];
foreach ($dayBuckets as $idx => $row) {
$day = $row['key_as_string'];
$amount = $row['amount']['value'];
// I want to extract the following code
$amountPer = 0;
if (isset($row['amount_deriv']) && $idx > 0) {
$amountDeriv = $row['amount_deriv']['value'];
$lastDayAmount = $dayBuckets[$idx - 1]['amount']['value'];
if ($lastDayAmount > 0) {
$amountPer = round(($amountDeriv / $lastDayAmount) * 100, 2);
}
}
...
When I tried to extract these code, the result is:
list($amountPer, $row) = $this->calAmountPer($row, $idx, $dayBuckets);
public function calAmountPer($row, int $idx, $dayBuckets): array
{
$amountPer = 0;
if (isset($row['amount_deriv']) && $idx > 0) {
$amountDeriv = $row['amount_deriv']['value'];
// WRONG!!!!
$lastDayAmount = $dayBuckets;
if ($lastDayAmount > 0) {
$amountPer = round(($amountDeriv / $lastDayAmount) * 100, 2);
}
}
return array($amountPer, $row);
}
The $dayBuckets is wrong.
When I only copy the code with out the loop, then extract these code, the result is correct.
请先登录再写评论。
On first glance, this report looks related:
https://youtrack.jetbrains.com/issue/WI-55369
It is curious that adding a PHPDoc like `
seems to fix the issue. Could you please try it too?
Thank you, I tried this, and now is correct.
But I may not be able to notice every code block every time when I tried to extract my code. Will this be fixed?
Thanks for checking this one.
Currently, this ticket is in the "Reponed" state, so we may expect it to be fixed. However, there is no ETA that I may share, sorry.