3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Scope a query to only include soft-deleted users with impending grace period. * * The user's grace period is considered impending if there are less than * a certain amount of days remaining before the hard deletion of that user. * * @param Builder $query The query to scope. * @param null|int $daysLeft The maximum amount of days remaining to consider the grace period impending. * @param bool $exact Whether to only include users having exactly `$daysLeft` days left to hard deletion. * * @return void * * @throws LogicException * @throws InvalidArgumentException */ #[Scope] protected function deletionGraceImpending ( Builder $query, ?int $daysLeft = null, bool $exact = false ): void { $graceDays = (int) config('user.delete_grace_days', 30); $daysLeft = (int) ($daysLeft ?? config('user.delete_grace_notify_days', 7)); $now = Carbon::now(); if($graceDays <= 0) { throw new LogicException( 'The grace period must be a positive number of days.' . 'Check the `user.delete_grace_days` configuration.' ); } if ($daysLeft < 0) { throw new InvalidArgumentException('The value of $daysLeft cannot be negative.'); } elseif ($daysLeft === 0) { Log::warning('The value of $daysLeft is zero. Returning empty result.'); $query->whereRaw('1 = 0'); return; } elseif ($daysLeft > $graceDays) { Log::warning("daysLeft ({$daysLeft}) exceeds graceDays ({$graceDays}). Returning empty result."); $query->whereRaw('1 = 0'); return; } // Calculate the proper bounds for 'deleted_at'. // For the user to be included in query results, the following inequality should hold: // $lowerBound ⩽ deleted_at ⩽ $upperBound $lowerBound = $now->copy()->subDays($graceDays); $upperBound = $now->copy()->subDays($graceDays - $daysLeft); if($exact) $lowerBound = $upperBound->copy()->subDay()->addSecond(); $interval = CarbonPeriod::create($lowerBound, $upperBound); $query->onlyTrashed()->whereBetween('deleted_at', $interval); }
Output for git.master_jit, git.master
Parse error: syntax error, unexpected token "protected" in /in/nKqhD on line 19
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
136.27 ms | 999 KiB | 7 Q