diff --git a/src/Illuminate/Auth/Passwords/PasswordBroker.php b/src/Illuminate/Auth/Passwords/PasswordBroker.php index 29ef2f9cbce..96e3130f9e6 100755 --- a/src/Illuminate/Auth/Passwords/PasswordBroker.php +++ b/src/Illuminate/Auth/Passwords/PasswordBroker.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Auth\Events\PasswordResetLinkSent; +use Illuminate\Auth\Passwords\PasswordResetResult; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; use Illuminate\Contracts\Auth\PasswordBroker as PasswordBrokerContract; use Illuminate\Contracts\Auth\UserProvider; @@ -64,17 +65,17 @@ public function sendResetLink(#[\SensitiveParameter] array $credentials, ?Closur $user = $this->getUser($credentials); if (is_null($user)) { - return static::INVALID_USER; + return PasswordResetResult::InvalidUser; } if ($this->tokens->recentlyCreatedToken($user)) { - return static::RESET_THROTTLED; + return PasswordResetResult::Throttled; } $token = $this->tokens->create($user); if ($callback) { - return $callback($user, $token) ?? static::RESET_LINK_SENT; + return $callback($user, $token) ?? PasswordResetResult::ResetLinkSent; } // Once we have the reset token, we are ready to send the message out to this @@ -84,7 +85,7 @@ public function sendResetLink(#[\SensitiveParameter] array $credentials, ?Closur $this->events?->dispatch(new PasswordResetLinkSent($user)); - return static::RESET_LINK_SENT; + return PasswordResetResult::ResetLinkSent; } /** @@ -114,7 +115,7 @@ public function reset(#[\SensitiveParameter] array $credentials, Closure $callba $this->tokens->delete($user); - return static::PASSWORD_RESET; + return PasswordResetResult::PasswordReset; } /** @@ -126,11 +127,11 @@ public function reset(#[\SensitiveParameter] array $credentials, Closure $callba protected function validateReset(#[\SensitiveParameter] array $credentials) { if (is_null($user = $this->getUser($credentials))) { - return static::INVALID_USER; + return PasswordResetResult::InvalidUser; } if (! $this->tokens->exists($user, $credentials['token'])) { - return static::INVALID_TOKEN; + return PasswordResetResult::InvalidToken; } return $user; diff --git a/src/Illuminate/Auth/Passwords/PasswordResetResult.php b/src/Illuminate/Auth/Passwords/PasswordResetResult.php new file mode 100644 index 00000000000..9b02dcb51e5 --- /dev/null +++ b/src/Illuminate/Auth/Passwords/PasswordResetResult.php @@ -0,0 +1,31 @@ + $seconds * @return $this */ protected function repeatEvery($seconds) @@ -250,7 +253,7 @@ public function hourly() /** * Schedule the event to run hourly at a given offset in the hour. * - * @param array|string|int $offset + * @param array|string|int<0, 24>|int<0, 24>[] $offset * @return $this */ public function hourlyAt($offset) @@ -353,8 +356,8 @@ public function dailyAt($time) /** * Schedule the event to run twice daily. * - * @param int $first - * @param int $second + * @param int $first<0, 24> + * @param int $second<0, 24> * @return $this */ public function twiceDaily($first = 1, $second = 13) @@ -365,9 +368,9 @@ public function twiceDaily($first = 1, $second = 13) /** * Schedule the event to run twice daily at a given offset. * - * @param int $first - * @param int $second - * @param int $offset + * @param int $first<0, 24> + * @param int $second<0, 24> + * @param int $offset<0, 59> * @return $this */ public function twiceDailyAt($first = 1, $second = 13, $offset = 0) @@ -380,8 +383,8 @@ public function twiceDailyAt($first = 1, $second = 13, $offset = 0) /** * Schedule the event to run at the given minutes and hours. * - * @param array|string|int $minutes - * @param array|string|int $hours + * @param array|string|int<0, 59> $minutes + * @param array|string|int<0, 24> $hours * @return $this */ protected function hourBasedSchedule($minutes, $hours) @@ -401,7 +404,7 @@ protected function hourBasedSchedule($minutes, $hours) */ public function weekdays() { - return $this->days(Schedule::MONDAY.'-'.Schedule::FRIDAY); + return $this->days(Day::Monday->value.'-'.Day::Friday->value); } /** @@ -411,7 +414,7 @@ public function weekdays() */ public function weekends() { - return $this->days(Schedule::SATURDAY.','.Schedule::SUNDAY); + return $this->days(Day::Saturday->value.','.Day::Sunday->value); } /** @@ -421,7 +424,7 @@ public function weekends() */ public function mondays() { - return $this->days(Schedule::MONDAY); + return $this->days(Day::Monday); } /** @@ -431,7 +434,7 @@ public function mondays() */ public function tuesdays() { - return $this->days(Schedule::TUESDAY); + return $this->days(Day::Tuesday); } /** @@ -441,7 +444,7 @@ public function tuesdays() */ public function wednesdays() { - return $this->days(Schedule::WEDNESDAY); + return $this->days(Day::Wednesday); } /** @@ -451,7 +454,7 @@ public function wednesdays() */ public function thursdays() { - return $this->days(Schedule::THURSDAY); + return $this->days(Day::Thursday); } /** @@ -461,7 +464,7 @@ public function thursdays() */ public function fridays() { - return $this->days(Schedule::FRIDAY); + return $this->days(Day::Friday); } /** @@ -471,7 +474,7 @@ public function fridays() */ public function saturdays() { - return $this->days(Schedule::SATURDAY); + return $this->days(Day::Saturday); } /** @@ -481,7 +484,7 @@ public function saturdays() */ public function sundays() { - return $this->days(Schedule::SUNDAY); + return $this->days(Day::Sunday); } /** @@ -499,7 +502,7 @@ public function weekly() /** * Schedule the event to run weekly on a given day and time. * - * @param array|mixed $dayOfWeek + * @param Day[]|Day|array|int|int[]|mixed $dayOfWeek * @param string $time * @return $this */ @@ -525,7 +528,7 @@ public function monthly() /** * Schedule the event to run monthly on a given day and time. * - * @param int $dayOfMonth + * @param int<0, 31> $dayOfMonth * @param string $time * @return $this */ @@ -539,8 +542,8 @@ public function monthlyOn($dayOfMonth = 1, $time = '0:0') /** * Schedule the event to run twice monthly at a given time. * - * @param int $first - * @param int $second + * @param int $first<0, 31> + * @param int $second<0, 31> * @param string $time * @return $this */ @@ -610,8 +613,8 @@ public function yearly() /** * Schedule the event to run yearly on a given month, day, and time. * - * @param int $month - * @param int|string $dayOfMonth + * @param int<1, 12> $month + * @param int<0, 31>|string $dayOfMonth * @param string $time * @return $this */ @@ -626,13 +629,15 @@ public function yearlyOn($month = 1, $dayOfMonth = 1, $time = '0:0') /** * Set the days of the week the command should run on. * - * @param array|mixed $days + * @param Day[]|Day|array|int[]|int|string[]|string|mixed $days * @return $this */ public function days($days) { $days = is_array($days) ? $days : func_get_args(); + $days = array_map(enum_value(...), $days); + return $this->spliceIntoPosition(5, implode(',', $days)); } @@ -660,7 +665,7 @@ protected function spliceIntoPosition($position, $value) { $segments = preg_split("/\s+/", $this->expression); - $segments[$position - 1] = $value; + $segments[$position - 1] = enum_value($value); return $this->cron(implode(' ', $segments)); } diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index 839d3627212..3736e9c4ab0 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -29,17 +29,11 @@ class Schedule } const SUNDAY = 0; - const MONDAY = 1; - const TUESDAY = 2; - const WEDNESDAY = 3; - const THURSDAY = 4; - const FRIDAY = 5; - const SATURDAY = 6; /** diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 1dd228fb907..c63f91f914c 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -232,7 +232,7 @@ protected function registerTimeoutHandler($job, WorkerOptions $options) )); } - $this->kill(static::EXIT_ERROR, $options); + $this->kill(self::EXIT_ERROR, $options); }, true); pcntl_alarm( @@ -304,12 +304,12 @@ protected function pauseWorker(WorkerOptions $options, $lastRestart) protected function stopIfNecessary(WorkerOptions $options, $lastRestart, $startTime = 0, $jobsProcessed = 0, $job = null) { return match (true) { - $this->shouldQuit => static::EXIT_SUCCESS, - $this->memoryExceeded($options->memory) => static::EXIT_MEMORY_LIMIT, - $this->queueShouldRestart($lastRestart) => static::EXIT_SUCCESS, - $options->stopWhenEmpty && is_null($job) => static::EXIT_SUCCESS, - $options->maxTime && hrtime(true) / 1e9 - $startTime >= $options->maxTime => static::EXIT_SUCCESS, - $options->maxJobs && $jobsProcessed >= $options->maxJobs => static::EXIT_SUCCESS, + $this->shouldQuit => self::EXIT_SUCCESS, + $this->memoryExceeded($options->memory) => self::EXIT_MEMORY_LIMIT, + $this->queueShouldRestart($lastRestart) => self::EXIT_SUCCESS, + $options->stopWhenEmpty && is_null($job) => self::EXIT_SUCCESS, + $options->maxTime && hrtime(true) / 1e9 - $startTime >= $options->maxTime => self::EXIT_SUCCESS, + $options->maxJobs && $jobsProcessed >= $options->maxJobs => self::EXIT_SUCCESS, default => null }; } diff --git a/src/Illuminate/Support/Facades/Password.php b/src/Illuminate/Support/Facades/Password.php index 87d9daf6fb1..cbcecc6795a 100755 --- a/src/Illuminate/Support/Facades/Password.php +++ b/src/Illuminate/Support/Facades/Password.php @@ -2,7 +2,7 @@ namespace Illuminate\Support\Facades; -use Illuminate\Contracts\Auth\PasswordBroker; +use Illuminate\Auth\Passwords\PasswordResetResult; /** * @method static \Illuminate\Contracts\Auth\PasswordBroker broker(string|null $name = null) @@ -26,35 +26,35 @@ class Password extends Facade * * @var string */ - const RESET_LINK_SENT = PasswordBroker::RESET_LINK_SENT; + const RESET_LINK_SENT = PasswordResetResult::ResetLinkSent; /** * Constant representing a successfully reset password. * * @var string */ - const PASSWORD_RESET = PasswordBroker::PASSWORD_RESET; + const PASSWORD_RESET = PasswordResetResult::PasswordReset; /** * Constant representing the user not found response. * * @var string */ - const INVALID_USER = PasswordBroker::INVALID_USER; + const INVALID_USER = PasswordResetResult::InvalidUser; /** * Constant representing an invalid token. * * @var string */ - const INVALID_TOKEN = PasswordBroker::INVALID_TOKEN; + const INVALID_TOKEN = PasswordResetResult::InvalidToken; /** * Constant representing a throttled reset attempt. * * @var string */ - const RESET_THROTTLED = PasswordBroker::RESET_THROTTLED; + const RESET_THROTTLED = PasswordResetResult::Throttled; /** * Get the registered name of the component. diff --git a/src/Illuminate/Support/Facades/Schedule.php b/src/Illuminate/Support/Facades/Schedule.php index 3c22681f5fc..42fe487df0e 100644 --- a/src/Illuminate/Support/Facades/Schedule.php +++ b/src/Illuminate/Support/Facades/Schedule.php @@ -50,7 +50,7 @@ * @method static \Illuminate\Console\Scheduling\PendingEventAttributes everyFifteenMinutes() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes everyThirtyMinutes() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes hourly() - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes hourlyAt(array|string|int $offset) + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes hourlyAt(array|string|int<0, 24> $offset) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes everyOddHour(array|string|int $offset = 0) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes everyTwoHours(array|string|int $offset = 0) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes everyThreeHours(array|string|int $offset = 0) @@ -59,8 +59,8 @@ * @method static \Illuminate\Console\Scheduling\PendingEventAttributes daily() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes at(string $time) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes dailyAt(string $time) - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes twiceDaily(int $first = 1, int $second = 13) - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes twiceDailyAt(int $first = 1, int $second = 13, int $offset = 0) + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes twiceDaily(int<0, 24> $first = 1, int<0, 24> $second = 13) + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes twiceDailyAt(int<0, 24> $first = 1, int<0, 24> $second = 13, int<0, 59> $offset = 0) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes weekdays() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes weekends() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes mondays() @@ -71,16 +71,16 @@ * @method static \Illuminate\Console\Scheduling\PendingEventAttributes saturdays() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes sundays() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes weekly() - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes weeklyOn(array|mixed $dayOfWeek, string $time = '0:0') + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes weeklyOn(array|int|int[]|\Illuminate\Console\Scheduling\Enums\Day|Illuminate\Console\Scheduling\Enums\Day[]|mixed $dayOfWeek, string $time = '0:0') * @method static \Illuminate\Console\Scheduling\PendingEventAttributes monthly() - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes monthlyOn(int $dayOfMonth = 1, string $time = '0:0') - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes twiceMonthly(int $first = 1, int $second = 16, string $time = '0:0') + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes monthlyOn(int<0, 31> $dayOfMonth = 1, string $time = '0:0') + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes twiceMonthly(int<0, 31> $first = 1, int<0, 31> $second = 16, string $time = '0:0') * @method static \Illuminate\Console\Scheduling\PendingEventAttributes lastDayOfMonth(string $time = '0:0') * @method static \Illuminate\Console\Scheduling\PendingEventAttributes quarterly() * @method static \Illuminate\Console\Scheduling\PendingEventAttributes quarterlyOn(int $dayOfQuarter = 1, string $time = '0:0') * @method static \Illuminate\Console\Scheduling\PendingEventAttributes yearly() - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes yearlyOn(int $month = 1, int|string $dayOfMonth = 1, string $time = '0:0') - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes days(array|mixed $days) + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes yearlyOn(int<1, 12> $month = 1, int<0, 31>|string $dayOfMonth = 1, string $time = '0:0') + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes days(array|\Illuminate\Console\Scheduling\Enums\Day|Illuminate\Console\Scheduling\Enums\Day[]|int|int[]|string|string[]|mixed $days) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes timezone(\DateTimeZone|string $timezone) * * @see \Illuminate\Console\Scheduling\Schedule