Larave Extracting Two Dates Out of One

Extracting two dates out of one, like in the case of startOfMonth & endOfMonth, make sure not to apply both functions on the same date variable. Otherwise, you get unexpected results. ๐Ÿ‘‡

class GetUserTokesConsuemed
{
  public function execute(User $user, Carbon $date = null):mixed
  {
    $date = $date ?? Carbon::now();
    
    // โŒ don't do
    $startDate = $date->startOfMonth();
    $endDate = $date->endOfMonth();
    
    // โœ”๏ธ do
    $startDate = $date->startOfMonth();
    $endDate = $date->copy()->endOfMonth(); // make a copy
    
    // ...
  }
}