因为你不需要这条线
$freeSlots = 0; //Unused local variable 'freeSlots'. The value of the variable is overwritten immediately.
由于IDE告诉此变量将被此行立即覆盖:
$freeSlots = (5 - $startSlot) + ($endSlot - 1);
所以第一行实际上是一条完全没必要的行,可以删除.你永远不会使用$ freeSlots,你正在重新定义它.
澄清范围:
$freeSlots = 0; //Unused local variable 'freeSlots'. The value of the variable is overwritten immediately. if (strtotime($endDate) === strtotime($startDate)) { return $endSlot - $startSlot; } $freeSlots = (5 - $startSlot) + ($endSlot - 1); $newTime = strtotime('+1 day', $newTime); if (date("Y-m-d", $newTime) === $endDate) { return $freeSlots; } do { if (!(date('N', $newTime) >= 6)) { $freeSlots += 4; } $newTime = strtotime('+1 day', $newTime); } while (date("Y-m-d", $newTime) !== $endDate); return $freeSlots; //but is clearly used here
上面的代码与您的代码完全相同.你不需要使用else
.如果条件为真,那么您将返回一个值.否则你继续.不需要别的.所以这是相同的范围.
因为你不需要这条线
$freeSlots = 0; //Unused local variable 'freeSlots'. The value of the variable is overwritten immediately.
由于IDE告诉此变量将被此行立即覆盖:
$freeSlots = (5 - $startSlot) + ($endSlot - 1);
所以第一行实际上是一条完全没必要的行,可以删除.你永远不会使用$ freeSlots,你正在重新定义它.
澄清范围:
$freeSlots = 0; //Unused local variable 'freeSlots'. The value of the variable is overwritten immediately. if (strtotime($endDate) === strtotime($startDate)) { return $endSlot - $startSlot; } $freeSlots = (5 - $startSlot) + ($endSlot - 1); $newTime = strtotime('+1 day', $newTime); if (date("Y-m-d", $newTime) === $endDate) { return $freeSlots; } do { if (!(date('N', $newTime) >= 6)) { $freeSlots += 4; } $newTime = strtotime('+1 day', $newTime); } while (date("Y-m-d", $newTime) !== $endDate); return $freeSlots; //but is clearly used here
上面的代码与您的代码完全相同.你不需要使用else
.如果条件为真,那么您将返回一个值.否则你继续.不需要别的.所以这是相同的范围.