From 88cc256c9c11e5dc8275fa0fb259eac3075faa8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:53:15 +0100 Subject: [PATCH 01/16] Date-specific enums and constants --- src/Illuminate/Cache/RateLimiter.php | 8 +++-- src/Illuminate/Cache/RateLimiting/Limit.php | 12 ++++--- .../Console/Scheduling/ManagesFrequencies.php | 34 +++++++++++-------- src/Illuminate/Log/LogManager.php | 4 ++- .../Routing/Middleware/ThrottleRequests.php | 4 ++- src/Illuminate/Support/Date/Day.php | 14 ++++++++ src/Illuminate/Support/Date/Month.php | 19 +++++++++++ src/Illuminate/Support/Date/constants.php | 23 +++++++++++++ src/Illuminate/Support/Facades/Schedule.php | 4 +-- 9 files changed, 96 insertions(+), 26 deletions(-) create mode 100644 src/Illuminate/Support/Date/Day.php create mode 100644 src/Illuminate/Support/Date/Month.php create mode 100644 src/Illuminate/Support/Date/constants.php diff --git a/src/Illuminate/Cache/RateLimiter.php b/src/Illuminate/Cache/RateLimiter.php index 8d8afe30a14c..6e65b4f12a54 100644 --- a/src/Illuminate/Cache/RateLimiter.php +++ b/src/Illuminate/Cache/RateLimiter.php @@ -7,6 +7,8 @@ use Illuminate\Support\Collection; use Illuminate\Support\InteractsWithTime; +use const Illuminate\Support\Date\SECONDS_PER_MINUTE; + use function Illuminate\Support\enum_value; class RateLimiter @@ -144,7 +146,7 @@ public function tooManyAttempts($key, $maxAttempts) * @param int $decaySeconds * @return int */ - public function hit($key, $decaySeconds = 60) + public function hit($key, $decaySeconds = SECONDS_PER_MINUTE) { return $this->increment($key, $decaySeconds); } @@ -157,7 +159,7 @@ public function hit($key, $decaySeconds = 60) * @param int $amount * @return int */ - public function increment($key, $decaySeconds = 60, $amount = 1) + public function increment($key, $decaySeconds = SECONDS_PER_MINUTE, $amount = 1) { $key = $this->cleanRateLimiterKey($key); @@ -184,7 +186,7 @@ public function increment($key, $decaySeconds = 60, $amount = 1) * @param int $amount * @return int */ - public function decrement($key, $decaySeconds = 60, $amount = 1) + public function decrement($key, $decaySeconds = SECONDS_PER_MINUTE, $amount = 1) { return $this->increment($key, $decaySeconds, $amount * -1); } diff --git a/src/Illuminate/Cache/RateLimiting/Limit.php b/src/Illuminate/Cache/RateLimiting/Limit.php index ed4c20258fe2..b8deae8ca624 100644 --- a/src/Illuminate/Cache/RateLimiting/Limit.php +++ b/src/Illuminate/Cache/RateLimiting/Limit.php @@ -2,6 +2,8 @@ namespace Illuminate\Cache\RateLimiting; +use const Illuminate\Support\Date\{SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY}; + class Limit { /** @@ -40,7 +42,7 @@ class Limit * @param int $decaySeconds * @return void */ - public function __construct($key = '', int $maxAttempts = 60, int $decaySeconds = 60) + public function __construct($key = '', int $maxAttempts = 60, int $decaySeconds = SECONDS_PER_MINUTE) { $this->key = $key; $this->maxAttempts = $maxAttempts; @@ -68,7 +70,7 @@ public static function perSecond($maxAttempts, $decaySeconds = 1) */ public static function perMinute($maxAttempts, $decayMinutes = 1) { - return new static('', $maxAttempts, 60 * $decayMinutes); + return new static('', $maxAttempts, MINUTES_PER_HOUR * $decayMinutes); } /** @@ -80,7 +82,7 @@ public static function perMinute($maxAttempts, $decayMinutes = 1) */ public static function perMinutes($decayMinutes, $maxAttempts) { - return new static('', $maxAttempts, 60 * $decayMinutes); + return new static('', $maxAttempts, MINUTES_PER_HOUR * $decayMinutes); } /** @@ -92,7 +94,7 @@ public static function perMinutes($decayMinutes, $maxAttempts) */ public static function perHour($maxAttempts, $decayHours = 1) { - return new static('', $maxAttempts, 60 * 60 * $decayHours); + return new static('', $maxAttempts, SECONDS_PER_MINUTE * MINUTES_PER_HOUR * $decayHours); } /** @@ -104,7 +106,7 @@ public static function perHour($maxAttempts, $decayHours = 1) */ public static function perDay($maxAttempts, $decayDays = 1) { - return new static('', $maxAttempts, 60 * 60 * 24 * $decayDays); + return new static('', $maxAttempts, SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY * $decayDays); } /** diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index d974a91b769e..0e471e648340 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -3,8 +3,12 @@ namespace Illuminate\Console\Scheduling; use Illuminate\Support\Carbon; +use Illuminate\Support\Date\Day; +use Illuminate\Support\Date\Month; use InvalidArgumentException; +use function Illuminate\Support\enum_value; + trait ManagesFrequencies { /** @@ -401,7 +405,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 +415,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 +425,7 @@ public function weekends() */ public function mondays() { - return $this->days(Schedule::MONDAY); + return $this->days(Day::MONDAY); } /** @@ -431,7 +435,7 @@ public function mondays() */ public function tuesdays() { - return $this->days(Schedule::TUESDAY); + return $this->days(Day::TUESDAY); } /** @@ -441,7 +445,7 @@ public function tuesdays() */ public function wednesdays() { - return $this->days(Schedule::WEDNESDAY); + return $this->days(Day::WEDNESDAY); } /** @@ -451,7 +455,7 @@ public function wednesdays() */ public function thursdays() { - return $this->days(Schedule::THURSDAY); + return $this->days(Day::THURSDAY); } /** @@ -461,7 +465,7 @@ public function thursdays() */ public function fridays() { - return $this->days(Schedule::FRIDAY); + return $this->days(Day::FRIDAY); } /** @@ -471,7 +475,7 @@ public function fridays() */ public function saturdays() { - return $this->days(Schedule::SATURDAY); + return $this->days(Day::SATURDAY); } /** @@ -481,7 +485,7 @@ public function saturdays() */ public function sundays() { - return $this->days(Schedule::SUNDAY); + return $this->days(Day::SUNDAY); } /** @@ -499,7 +503,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 */ @@ -610,7 +614,7 @@ public function yearly() /** * Schedule the event to run yearly on a given month, day, and time. * - * @param int $month + * @param int|\Illuminate\Support\Date\Month $month * @param int|string $dayOfMonth * @param string $time * @return $this @@ -620,19 +624,21 @@ public function yearlyOn($month = 1, $dayOfMonth = 1, $time = '0:0') $this->dailyAt($time); return $this->spliceIntoPosition(3, $dayOfMonth) - ->spliceIntoPosition(4, $month); + ->spliceIntoPosition(4, enum_value($month)); } /** * Set the days of the week the command should run on. * - * @param array|mixed $days + * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\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 +666,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/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 7563e35cb837..4c9330469b02 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -23,6 +23,8 @@ use Psr\Log\LoggerInterface; use Throwable; +use const Illuminate\Support\Date\DAYS_PER_WEEK; + /** * @mixin \Illuminate\Log\Logger */ @@ -328,7 +330,7 @@ protected function createDailyDriver(array $config) { return new Monolog($this->parseChannel($config), [ $this->prepareHandler(new RotatingFileHandler( - $config['path'], $config['days'] ?? 7, $this->level($config), + $config['path'], $config['days'] ?? DAYS_PER_WEEK, $this->level($config), $config['bubble'] ?? true, $config['permission'] ?? null, $config['locking'] ?? false ), $config), ], $config['replace_placeholders'] ?? false ? [new PsrLogMessageProcessor()] : []); diff --git a/src/Illuminate/Routing/Middleware/ThrottleRequests.php b/src/Illuminate/Routing/Middleware/ThrottleRequests.php index d9859558c30c..049dea8923cf 100644 --- a/src/Illuminate/Routing/Middleware/ThrottleRequests.php +++ b/src/Illuminate/Routing/Middleware/ThrottleRequests.php @@ -13,6 +13,8 @@ use RuntimeException; use Symfony\Component\HttpFoundation\Response; +use const Illuminate\Support\Date\SECONDS_PER_MINUTE; + class ThrottleRequests { use InteractsWithTime; @@ -96,7 +98,7 @@ public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes (object) [ 'key' => $prefix.$this->resolveRequestSignature($request), 'maxAttempts' => $this->resolveMaxAttempts($request, $maxAttempts), - 'decaySeconds' => 60 * $decayMinutes, + 'decaySeconds' => SECONDS_PER_DAY * $decayMinutes, 'responseCallback' => null, ], ] diff --git a/src/Illuminate/Support/Date/Day.php b/src/Illuminate/Support/Date/Day.php new file mode 100644 index 000000000000..be71427bed53 --- /dev/null +++ b/src/Illuminate/Support/Date/Day.php @@ -0,0 +1,14 @@ + Date: Thu, 19 Dec 2024 21:56:17 +0100 Subject: [PATCH 02/16] Imports order --- src/Illuminate/Cache/RateLimiter.php | 4 ++-- src/Illuminate/Cache/RateLimiting/Limit.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Cache/RateLimiter.php b/src/Illuminate/Cache/RateLimiter.php index 6e65b4f12a54..d9c7dfec9109 100644 --- a/src/Illuminate/Cache/RateLimiter.php +++ b/src/Illuminate/Cache/RateLimiter.php @@ -7,10 +7,10 @@ use Illuminate\Support\Collection; use Illuminate\Support\InteractsWithTime; -use const Illuminate\Support\Date\SECONDS_PER_MINUTE; - use function Illuminate\Support\enum_value; +use const Illuminate\Support\Date\SECONDS_PER_MINUTE; + class RateLimiter { use InteractsWithTime; diff --git a/src/Illuminate/Cache/RateLimiting/Limit.php b/src/Illuminate/Cache/RateLimiting/Limit.php index b8deae8ca624..a5d636004f4a 100644 --- a/src/Illuminate/Cache/RateLimiting/Limit.php +++ b/src/Illuminate/Cache/RateLimiting/Limit.php @@ -2,7 +2,7 @@ namespace Illuminate\Cache\RateLimiting; -use const Illuminate\Support\Date\{SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY}; +use const Illuminate\Support\Date\{HOURS_PER_DAY, MINUTES_PER_HOUR, SECONDS_PER_MINUTE}; class Limit { From 0cf1eccab8c3a8ea0531672b8aac0f2cfd443ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:56:29 +0100 Subject: [PATCH 03/16] Fix typo --- src/Illuminate/Routing/Middleware/ThrottleRequests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Middleware/ThrottleRequests.php b/src/Illuminate/Routing/Middleware/ThrottleRequests.php index 049dea8923cf..8ee0e15a0089 100644 --- a/src/Illuminate/Routing/Middleware/ThrottleRequests.php +++ b/src/Illuminate/Routing/Middleware/ThrottleRequests.php @@ -98,7 +98,7 @@ public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes (object) [ 'key' => $prefix.$this->resolveRequestSignature($request), 'maxAttempts' => $this->resolveMaxAttempts($request, $maxAttempts), - 'decaySeconds' => SECONDS_PER_DAY * $decayMinutes, + 'decaySeconds' => SECONDS_PER_MINUTE * $decayMinutes, 'responseCallback' => null, ], ] From a1d1d48c1e125d05386aa927592bdf63e6516366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:59:14 +0100 Subject: [PATCH 04/16] Add constants to autoloader --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index f39a7a8229a3..66b8151660d2 100644 --- a/composer.json +++ b/composer.json @@ -138,6 +138,7 @@ "src/Illuminate/Filesystem/functions.php", "src/Illuminate/Foundation/helpers.php", "src/Illuminate/Log/functions.php", + "src/Illuminate/Support/Date/constants.php", "src/Illuminate/Support/functions.php", "src/Illuminate/Support/helpers.php" ], From 37be0fd515189f638f536bb3c7a607778c312155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:05:46 +0100 Subject: [PATCH 05/16] Namespace constants --- src/Illuminate/Support/Date/constants.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Support/Date/constants.php b/src/Illuminate/Support/Date/constants.php index bd9533cb5969..d261a673cdad 100644 --- a/src/Illuminate/Support/Date/constants.php +++ b/src/Illuminate/Support/Date/constants.php @@ -2,22 +2,22 @@ namespace Illuminate\Support\Date; -if (! defined('SECONDS_PER_MINUTE')) { - define('SECONDS_PER_MINUTE', 60); +if (! defined(__NAMESPACE__.'\\'.($constant = 'SECONDS_PER_MINUTE'))) { + define(__NAMESPACE__.'\\'.$constant, 60); } -if (! defined('MINUTES_PER_HOUR')) { - define('MINUTES_PER_HOUR', 60); +if (! defined(__NAMESPACE__.'\\'.($constant = 'MINUTES_PER_HOUR'))) { + define(__NAMESPACE__.'\\'.$constant, 60); } -if (! defined('HOURS_PER_DAY')) { - define('HOURS_PER_DAY', 24); +if (! defined(__NAMESPACE__.'\\'.($constant = 'HOURS_PER_DAY'))) { + define(__NAMESPACE__.'\\'.$constant, 24); } -if (! defined('DAYS_PER_WEEK')) { - define('DAYS_PER_WEEK', 7); +if (! defined(__NAMESPACE__.'\\'.($constant = 'DAYS_PER_WEEK'))) { + define(__NAMESPACE__.'\\'.$constant, 7); } -if (! defined('MONTHS_PER_YEAR')) { - define('MONTHS_PER_YEAR', 12); +if (! defined(__NAMESPACE__.'\\'.($constant = 'MONTHS_PER_YEAR'))) { + define(__NAMESPACE__.'\\'.$constant, 12); } From ece494272f8442ef3b3d5a1935e53cb67b841ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:07:05 +0100 Subject: [PATCH 06/16] Fix spacing --- src/Illuminate/Support/Date/constants.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Support/Date/constants.php b/src/Illuminate/Support/Date/constants.php index d261a673cdad..9e7b165b4918 100644 --- a/src/Illuminate/Support/Date/constants.php +++ b/src/Illuminate/Support/Date/constants.php @@ -2,22 +2,22 @@ namespace Illuminate\Support\Date; -if (! defined(__NAMESPACE__.'\\'.($constant = 'SECONDS_PER_MINUTE'))) { +if (! defined(__NAMESPACE__.'\\'.($constant = 'SECONDS_PER_MINUTE'))) { define(__NAMESPACE__.'\\'.$constant, 60); } -if (! defined(__NAMESPACE__.'\\'.($constant = 'MINUTES_PER_HOUR'))) { +if (! defined(__NAMESPACE__.'\\'.($constant = 'MINUTES_PER_HOUR'))) { define(__NAMESPACE__.'\\'.$constant, 60); } -if (! defined(__NAMESPACE__.'\\'.($constant = 'HOURS_PER_DAY'))) { +if (! defined(__NAMESPACE__.'\\'.($constant = 'HOURS_PER_DAY'))) { define(__NAMESPACE__.'\\'.$constant, 24); } -if (! defined(__NAMESPACE__.'\\'.($constant = 'DAYS_PER_WEEK'))) { +if (! defined(__NAMESPACE__.'\\'.($constant = 'DAYS_PER_WEEK'))) { define(__NAMESPACE__.'\\'.$constant, 7); } -if (! defined(__NAMESPACE__.'\\'.($constant = 'MONTHS_PER_YEAR'))) { +if (! defined(__NAMESPACE__.'\\'.($constant = 'MONTHS_PER_YEAR'))) { define(__NAMESPACE__.'\\'.$constant, 12); } From 7a33e21ac521ec5e717ba55a9d12fe4008db9de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:11:19 +0100 Subject: [PATCH 07/16] Fix casing --- .../Console/Scheduling/ManagesFrequencies.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index 0e471e648340..5867aaf2afe0 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -425,7 +425,7 @@ public function weekends() */ public function mondays() { - return $this->days(Day::MONDAY); + return $this->days(Day::Monday); } /** @@ -435,7 +435,7 @@ public function mondays() */ public function tuesdays() { - return $this->days(Day::TUESDAY); + return $this->days(Day::Tuesday); } /** @@ -445,7 +445,7 @@ public function tuesdays() */ public function wednesdays() { - return $this->days(Day::WEDNESDAY); + return $this->days(Day::Wednesday); } /** @@ -455,7 +455,7 @@ public function wednesdays() */ public function thursdays() { - return $this->days(Day::THURSDAY); + return $this->days(Day::Thursday); } /** @@ -465,7 +465,7 @@ public function thursdays() */ public function fridays() { - return $this->days(Day::FRIDAY); + return $this->days(Day::Friday); } /** @@ -475,7 +475,7 @@ public function fridays() */ public function saturdays() { - return $this->days(Day::SATURDAY); + return $this->days(Day::Saturday); } /** @@ -485,7 +485,7 @@ public function saturdays() */ public function sundays() { - return $this->days(Day::SUNDAY); + return $this->days(Day::Sunday); } /** From f2625d0bb4b8198de897ece91a182ac1c6c2bc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:11:49 +0100 Subject: [PATCH 08/16] Make PHPDoc block annotation style consistent --- src/Illuminate/Console/Scheduling/ManagesFrequencies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index 5867aaf2afe0..59fc01962291 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -503,7 +503,7 @@ public function weekly() /** * Schedule the event to run weekly on a given day and time. * - * @param Day[]|Day|array|int|int[]|mixed $dayOfWeek + * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\Day|array|int|int[]|mixed $dayOfWeek * @param string $time * @return $this */ From 00a80c5f9276037991190893b3f99da0fa866ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:19:27 +0100 Subject: [PATCH 09/16] Improve PHPDoc block constraints --- src/Illuminate/Console/Scheduling/ManagesFrequencies.php | 2 +- src/Illuminate/Support/Facades/Schedule.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index 59fc01962291..1c7c0a2ae591 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -630,7 +630,7 @@ public function yearlyOn($month = 1, $dayOfMonth = 1, $time = '0:0') /** * Set the days of the week the command should run on. * - * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\Day|array|int[]|int|string[]|string|mixed $days + * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\Day|array|int<0, 6>[]|int<0, 6>|string[]|string|mixed $days * @return $this */ public function days($days) diff --git a/src/Illuminate/Support/Facades/Schedule.php b/src/Illuminate/Support/Facades/Schedule.php index 47aee7462c1f..3eed2fbe899e 100644 --- a/src/Illuminate/Support/Facades/Schedule.php +++ b/src/Illuminate/Support/Facades/Schedule.php @@ -71,7 +71,7 @@ * @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|int|int[]|\Illuminate\Support\Date\Day|Illuminate\Support\Date\Day[]|mixed $dayOfWeek, string $time = '0:0') + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes weeklyOn(array|int<0, 6>|int<0, 6>[]|\Illuminate\Support\Date\Day|Illuminate\Support\Date\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') @@ -80,7 +80,7 @@ * @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|\Illuminate\Support\Date\Day|Illuminate\Support\Date\Day[]|int|int[]|string|string[]|mixed $days) + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes days(array|\Illuminate\Support\Date\Day|Illuminate\Support\Date\Day[]|int<0, 6>|int<0, 6>[]|string|string[]|mixed $days) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes timezone(\DateTimeZone|string $timezone) * * @see \Illuminate\Console\Scheduling\Schedule From b1347e514fa188bab9d916041c3e928082d8d501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:22:48 +0100 Subject: [PATCH 10/16] Document month constraints --- src/Illuminate/Console/Scheduling/ManagesFrequencies.php | 4 ++-- src/Illuminate/Support/Facades/Schedule.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index 1c7c0a2ae591..cc275f801e15 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -503,7 +503,7 @@ public function weekly() /** * Schedule the event to run weekly on a given day and time. * - * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\Day|array|int|int[]|mixed $dayOfWeek + * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\Day|array|int<0, 6>|int<0, 6>[]|mixed $dayOfWeek * @param string $time * @return $this */ @@ -614,7 +614,7 @@ public function yearly() /** * Schedule the event to run yearly on a given month, day, and time. * - * @param int|\Illuminate\Support\Date\Month $month + * @param int<1, 12>|\Illuminate\Support\Date\Month $month * @param int|string $dayOfMonth * @param string $time * @return $this diff --git a/src/Illuminate/Support/Facades/Schedule.php b/src/Illuminate/Support/Facades/Schedule.php index 3eed2fbe899e..86d36b70a3fe 100644 --- a/src/Illuminate/Support/Facades/Schedule.php +++ b/src/Illuminate/Support/Facades/Schedule.php @@ -79,7 +79,7 @@ * @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 yearlyOn(int<1, 12>|\Illuminate\Support\Date\Month $month = 1, int|string $dayOfMonth = 1, string $time = '0:0') * @method static \Illuminate\Console\Scheduling\PendingEventAttributes days(array|\Illuminate\Support\Date\Day|Illuminate\Support\Date\Day[]|int<0, 6>|int<0, 6>[]|string|string[]|mixed $days) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes timezone(\DateTimeZone|string $timezone) * From 3959819ad723041920272e508482658e5629e650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:49:19 +0100 Subject: [PATCH 11/16] Rename "Day" to "DayOfWeek" --- .../Console/Scheduling/ManagesFrequencies.php | 24 +++++++++---------- .../Support/Date/{Day.php => DayOfWeek.php} | 2 +- src/Illuminate/Support/Facades/Schedule.php | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) rename src/Illuminate/Support/Date/{Day.php => DayOfWeek.php} (90%) diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index e312cc401293..242fbced5d93 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -3,7 +3,7 @@ namespace Illuminate\Console\Scheduling; use Illuminate\Support\Carbon; -use Illuminate\Support\Date\Day; +use Illuminate\Support\Date\DayOfWeek; use Illuminate\Support\Date\Month; use InvalidArgumentException; @@ -405,7 +405,7 @@ protected function hourBasedSchedule($minutes, $hours) */ public function weekdays() { - return $this->days(Day::Monday->value.'-'.Day::Friday->value); + return $this->days(DayOfWeek::Monday->value.'-'.DayOfWeek::Friday->value); } /** @@ -415,7 +415,7 @@ public function weekdays() */ public function weekends() { - return $this->days(Day::Saturday->value.','.Day::Sunday->value); + return $this->days(DayOfWeek::Saturday->value.','.DayOfWeek::Sunday->value); } /** @@ -425,7 +425,7 @@ public function weekends() */ public function mondays() { - return $this->days(Day::Monday); + return $this->days(DayOfWeek::Monday); } /** @@ -435,7 +435,7 @@ public function mondays() */ public function tuesdays() { - return $this->days(Day::Tuesday); + return $this->days(DayOfWeek::Tuesday); } /** @@ -445,7 +445,7 @@ public function tuesdays() */ public function wednesdays() { - return $this->days(Day::Wednesday); + return $this->days(DayOfWeek::Wednesday); } /** @@ -455,7 +455,7 @@ public function wednesdays() */ public function thursdays() { - return $this->days(Day::Thursday); + return $this->days(DayOfWeek::Thursday); } /** @@ -465,7 +465,7 @@ public function thursdays() */ public function fridays() { - return $this->days(Day::Friday); + return $this->days(DayOfWeek::Friday); } /** @@ -475,7 +475,7 @@ public function fridays() */ public function saturdays() { - return $this->days(Day::Saturday); + return $this->days(DayOfWeek::Saturday); } /** @@ -485,7 +485,7 @@ public function saturdays() */ public function sundays() { - return $this->days(Day::Sunday); + return $this->days(DayOfWeek::Sunday); } /** @@ -503,7 +503,7 @@ public function weekly() /** * Schedule the event to run weekly on a given day and time. * - * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\Day|array|int<0, 6>|int<0, 6>[]|mixed $dayOfWeek + * @param \Illuminate\Support\Date\DayOfWeek[]|\Illuminate\Support\Date\DayOfWeek|array|int<0, 6>|int<0, 6>[]|mixed $dayOfWeek * @param string $time * @return $this */ @@ -630,7 +630,7 @@ public function yearlyOn($month = 1, $dayOfMonth = 1, $time = '0:0') /** * Set the days of the week the command should run on. * - * @param \Illuminate\Support\Date\Day[]|\Illuminate\Support\Date\Day|array|int<0, 6>[]|int<0, 6>|string[]|string|mixed $days + * @param \Illuminate\Support\Date\DayOfWeek[]|\Illuminate\Support\Date\DayOfWeek|array|int<0, 6>[]|int<0, 6>|string[]|string|mixed $days * @return $this */ public function days($days) diff --git a/src/Illuminate/Support/Date/Day.php b/src/Illuminate/Support/Date/DayOfWeek.php similarity index 90% rename from src/Illuminate/Support/Date/Day.php rename to src/Illuminate/Support/Date/DayOfWeek.php index be71427bed53..840067071eb7 100644 --- a/src/Illuminate/Support/Date/Day.php +++ b/src/Illuminate/Support/Date/DayOfWeek.php @@ -2,7 +2,7 @@ namespace Illuminate\Support\Date; -enum Day: int +enum DayOfWeek: int { case Sunday = 0; case Monday = 1; diff --git a/src/Illuminate/Support/Facades/Schedule.php b/src/Illuminate/Support/Facades/Schedule.php index 4d1fe7e225d9..78bbcbaec1a1 100644 --- a/src/Illuminate/Support/Facades/Schedule.php +++ b/src/Illuminate/Support/Facades/Schedule.php @@ -71,7 +71,7 @@ * @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|int<0, 6>|int<0, 6>[]|\Illuminate\Support\Date\Day|Illuminate\Support\Date\Day[]|mixed $dayOfWeek, string $time = '0:0') + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes weeklyOn(array|int<0, 6>|int<0, 6>[]|\Illuminate\Support\Date\DayOfWeek|Illuminate\Support\Date\DayOfWeek[]|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') @@ -80,7 +80,7 @@ * @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<1, 12>|\Illuminate\Support\Date\Month $month = 1, int|string $dayOfMonth = 1, string $time = '0:0') - * @method static \Illuminate\Console\Scheduling\PendingEventAttributes days(array|\Illuminate\Support\Date\Day|Illuminate\Support\Date\Day[]|int<0, 6>|int<0, 6>[]|string|string[]|mixed $days) + * @method static \Illuminate\Console\Scheduling\PendingEventAttributes days(array|\Illuminate\Support\Date\DayOfWeek|Illuminate\Support\Date\DayOfWeek[]|int<0, 6>|int<0, 6>[]|string|string[]|mixed $days) * @method static \Illuminate\Console\Scheduling\PendingEventAttributes timezone(\DateTimeZone|string $timezone) * * @see \Illuminate\Console\Scheduling\Schedule From 6b61419f0e984157560650a55cb8d7536122c3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:23:57 +0100 Subject: [PATCH 12/16] Add shortcut constants SECONDS_PER_HOUR and SECONDS_PER_DAY Co-authored-by: fragkp --- src/Illuminate/Cache/RateLimiting/Limit.php | 6 +++--- src/Illuminate/Support/Date/constants.php | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Cache/RateLimiting/Limit.php b/src/Illuminate/Cache/RateLimiting/Limit.php index a5d636004f4a..6ed2e1e7ddbc 100644 --- a/src/Illuminate/Cache/RateLimiting/Limit.php +++ b/src/Illuminate/Cache/RateLimiting/Limit.php @@ -2,7 +2,7 @@ namespace Illuminate\Cache\RateLimiting; -use const Illuminate\Support\Date\{HOURS_PER_DAY, MINUTES_PER_HOUR, SECONDS_PER_MINUTE}; +use const Illuminate\Support\Date\{SECONDS_PER_HOUR, SECONDS_PER_DAY}; class Limit { @@ -94,7 +94,7 @@ public static function perMinutes($decayMinutes, $maxAttempts) */ public static function perHour($maxAttempts, $decayHours = 1) { - return new static('', $maxAttempts, SECONDS_PER_MINUTE * MINUTES_PER_HOUR * $decayHours); + return new static('', $maxAttempts, SECONDS_PER_HOUR * $decayHours); } /** @@ -106,7 +106,7 @@ public static function perHour($maxAttempts, $decayHours = 1) */ public static function perDay($maxAttempts, $decayDays = 1) { - return new static('', $maxAttempts, SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY * $decayDays); + return new static('', $maxAttempts, SECONDS_PER_DAY * $decayDays); } /** diff --git a/src/Illuminate/Support/Date/constants.php b/src/Illuminate/Support/Date/constants.php index 9e7b165b4918..1f374e459440 100644 --- a/src/Illuminate/Support/Date/constants.php +++ b/src/Illuminate/Support/Date/constants.php @@ -14,6 +14,14 @@ define(__NAMESPACE__.'\\'.$constant, 24); } +if (! defined(__NAMESPACE__.'\\'.($constant = 'SECONDS_PER_HOUR'))) { + define(__NAMESPACE__.'\\'.$constant, SECONDS_PER_MINUTE * MINUTES_PER_HOUR); +} + +if (! defined(__NAMESPACE__.'\\'.($constant = 'SECONDS_PER_DAY'))) { + define(__NAMESPACE__.'\\'.$constant, SECONDS_PER_HOUR * HOURS_PER_DAY); +} + if (! defined(__NAMESPACE__.'\\'.($constant = 'DAYS_PER_WEEK'))) { define(__NAMESPACE__.'\\'.$constant, 7); } From 29a06e697c05ca20a29621575cc4131671d9b7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:24:42 +0100 Subject: [PATCH 13/16] Fix StyleCI --- src/Illuminate/Cache/RateLimiting/Limit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/RateLimiting/Limit.php b/src/Illuminate/Cache/RateLimiting/Limit.php index 6ed2e1e7ddbc..5f8d6f65ede3 100644 --- a/src/Illuminate/Cache/RateLimiting/Limit.php +++ b/src/Illuminate/Cache/RateLimiting/Limit.php @@ -2,7 +2,7 @@ namespace Illuminate\Cache\RateLimiting; -use const Illuminate\Support\Date\{SECONDS_PER_HOUR, SECONDS_PER_DAY}; +use const Illuminate\Support\Date\{SECONDS_PER_DAY, SECONDS_PER_HOUR}; class Limit { From 4494cc4f27dda35769467acecce8d223921226cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:29:20 +0100 Subject: [PATCH 14/16] Add missing constant to import --- src/Illuminate/Cache/RateLimiting/Limit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/RateLimiting/Limit.php b/src/Illuminate/Cache/RateLimiting/Limit.php index 5f8d6f65ede3..dda516faba3f 100644 --- a/src/Illuminate/Cache/RateLimiting/Limit.php +++ b/src/Illuminate/Cache/RateLimiting/Limit.php @@ -2,7 +2,7 @@ namespace Illuminate\Cache\RateLimiting; -use const Illuminate\Support\Date\{SECONDS_PER_DAY, SECONDS_PER_HOUR}; +use const Illuminate\Support\Date\{MINUTES_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_HOUR}; class Limit { From 4d677340d84539f7fe3509388109e7cf648309c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:31:55 +0100 Subject: [PATCH 15/16] Import SECONDS_PER_MINUTE --- src/Illuminate/Cache/RateLimiting/Limit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/RateLimiting/Limit.php b/src/Illuminate/Cache/RateLimiting/Limit.php index dda516faba3f..7357ff062a5a 100644 --- a/src/Illuminate/Cache/RateLimiting/Limit.php +++ b/src/Illuminate/Cache/RateLimiting/Limit.php @@ -2,7 +2,7 @@ namespace Illuminate\Cache\RateLimiting; -use const Illuminate\Support\Date\{MINUTES_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_HOUR}; +use const Illuminate\Support\Date\{MINUTES_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE}; class Limit { From 6692d2512cf66639bd76e0b327410fdc10924792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:47:45 +0100 Subject: [PATCH 16/16] Add constants to other places as well --- src/Illuminate/Cookie/CookieJar.php | 4 +++- src/Illuminate/Session/ArraySessionHandler.php | 4 +++- src/Illuminate/Session/CacheBasedSessionHandler.php | 4 +++- src/Illuminate/Session/CookieSessionHandler.php | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Cookie/CookieJar.php b/src/Illuminate/Cookie/CookieJar.php index 9eedc7de0f71..ac7875095bb7 100755 --- a/src/Illuminate/Cookie/CookieJar.php +++ b/src/Illuminate/Cookie/CookieJar.php @@ -8,6 +8,8 @@ use Illuminate\Support\Traits\Macroable; use Symfony\Component\HttpFoundation\Cookie; +use const Illuminate\Support\Date\SECONDS_PER_MINUTE; + class CookieJar implements JarContract { use InteractsWithTime, Macroable; @@ -65,7 +67,7 @@ public function make($name, $value, $minutes = 0, $path = null, $domain = null, { [$path, $domain, $secure, $sameSite] = $this->getPathAndDomain($path, $domain, $secure, $sameSite); - $time = ($minutes == 0) ? 0 : $this->availableAt($minutes * 60); + $time = ($minutes == 0) ? 0 : $this->availableAt($minutes * SECONDS_PER_MINUTE); return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly, $raw, $sameSite); } diff --git a/src/Illuminate/Session/ArraySessionHandler.php b/src/Illuminate/Session/ArraySessionHandler.php index 44d50dafd93e..5e59d1071ee1 100644 --- a/src/Illuminate/Session/ArraySessionHandler.php +++ b/src/Illuminate/Session/ArraySessionHandler.php @@ -5,6 +5,8 @@ use Illuminate\Support\InteractsWithTime; use SessionHandlerInterface; +use const Illuminate\Support\Date\SECONDS_PER_MINUTE; + class ArraySessionHandler implements SessionHandlerInterface { use InteractsWithTime; @@ -67,7 +69,7 @@ public function read($sessionId): string|false $session = $this->storage[$sessionId]; - $expiration = $this->calculateExpiration($this->minutes * 60); + $expiration = $this->calculateExpiration($this->minutes * SECONDS_PER_MINUTE); if (isset($session['time']) && $session['time'] >= $expiration) { return $session['data']; diff --git a/src/Illuminate/Session/CacheBasedSessionHandler.php b/src/Illuminate/Session/CacheBasedSessionHandler.php index 0cccdf2d922c..7ff7e5783388 100755 --- a/src/Illuminate/Session/CacheBasedSessionHandler.php +++ b/src/Illuminate/Session/CacheBasedSessionHandler.php @@ -5,6 +5,8 @@ use Illuminate\Contracts\Cache\Repository as CacheContract; use SessionHandlerInterface; +use const Illuminate\Support\Date\SECONDS_PER_MINUTE; + class CacheBasedSessionHandler implements SessionHandlerInterface { /** @@ -71,7 +73,7 @@ public function read($sessionId): string */ public function write($sessionId, $data): bool { - return $this->cache->put($sessionId, $data, $this->minutes * 60); + return $this->cache->put($sessionId, $data, $this->minutes * SECONDS_PER_MINUTE); } /** diff --git a/src/Illuminate/Session/CookieSessionHandler.php b/src/Illuminate/Session/CookieSessionHandler.php index 396022b37f4f..1160c6a0156e 100755 --- a/src/Illuminate/Session/CookieSessionHandler.php +++ b/src/Illuminate/Session/CookieSessionHandler.php @@ -7,6 +7,8 @@ use SessionHandlerInterface; use Symfony\Component\HttpFoundation\Request; +use const Illuminate\Support\Date\SECONDS_PER_MINUTE; + class CookieSessionHandler implements SessionHandlerInterface { use InteractsWithTime; @@ -100,7 +102,7 @@ public function write($sessionId, $data): bool { $this->cookie->queue($sessionId, json_encode([ 'data' => $data, - 'expires' => $this->availableAt($this->minutes * 60), + 'expires' => $this->availableAt($this->minutes * SECONDS_PER_MINUTE), ]), $this->expireOnClose ? 0 : $this->minutes); return true;