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); }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.140.0330.01217.50
8.4.130.0340.00917.46
8.4.120.0400.00717.30
8.4.110.0410.00617.71
8.4.100.0470.01017.70
8.4.90.0400.01017.70
8.4.80.0340.01417.73
8.4.70.0430.01017.42
8.4.60.0340.01217.80
8.4.50.0370.00917.60
8.4.40.0390.01017.37
8.4.30.0400.01017.65
8.4.20.0410.01117.47
8.4.10.0380.01117.58
8.3.270.0390.00516.33
8.3.260.0390.00716.65
8.3.250.0390.01016.60
8.3.240.0330.01216.57
8.3.230.0320.01316.66
8.3.220.0320.01316.77
8.3.210.0340.01016.81
8.3.200.0350.01016.83
8.3.190.0360.00916.53
8.3.180.0430.00216.77
8.3.170.0370.01016.29
8.3.160.0360.01116.52
8.3.150.0390.00916.72
8.3.140.0430.00616.65
8.3.130.0330.01116.37
8.3.120.0370.00516.38
8.3.110.0360.01016.61
8.3.100.0390.00916.53
8.3.90.0400.00816.34
8.3.80.0350.01316.69
8.3.70.0340.01316.31
8.3.60.0430.00516.74
8.3.50.0360.01116.51
8.3.40.0410.00917.31
8.3.30.0410.00317.52
8.3.20.0360.00617.29
8.3.10.0320.00517.61
8.3.00.0320.01117.39
8.2.290.0310.00716.36
8.2.280.0300.00816.85
8.2.270.0290.01016.47
8.2.260.0330.00716.30
8.2.250.0300.01016.63
8.2.240.0280.01116.47
8.2.230.0320.00716.24
8.2.220.0300.00916.40
8.2.210.0270.01116.38
8.2.200.0310.00916.39
8.2.190.0310.01016.67
8.2.180.0330.00616.54
8.2.170.0360.00917.74
8.2.160.0330.00817.42
8.2.150.0370.00517.50
8.2.140.0360.00717.35
8.2.130.0360.00517.36
8.2.120.0360.00617.37
8.2.110.0350.00917.52
8.2.100.0330.00817.43
8.2.90.0340.00717.55
8.2.80.0340.00717.61
8.2.70.0480.00817.28
8.2.60.0330.01017.39
8.2.50.0400.01117.42
8.2.40.0290.01117.32
8.2.30.0290.01017.28
8.2.20.0300.00817.41
8.2.10.0330.00617.33
8.2.00.0330.01117.44

preferences:
139.46 ms | 997 KiB | 7 Q