From 257e5cf194323780b9472982e637894c58ad2d8d Mon Sep 17 00:00:00 2001 From: takaram Date: Fri, 17 Feb 2023 19:11:57 +0000 Subject: [PATCH] Improve withTestNow() signature --- src/Carbon/CarbonInterface.php | 7 +++++-- src/Carbon/Factory.php | 2 +- src/Carbon/FactoryImmutable.php | 2 +- src/Carbon/Traits/Test.php | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Carbon/CarbonInterface.php b/src/Carbon/CarbonInterface.php index 0c9cc52a69..d63c4b8af2 100644 --- a/src/Carbon/CarbonInterface.php +++ b/src/Carbon/CarbonInterface.php @@ -5120,12 +5120,15 @@ public function weeksInYear($dayOfWeek = null, $dayOfYear = null); * * /!\ Use this method for unit tests only. * + * @template T + * * @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance - * @param Closure|null $callback + * @param Closure(): T $callback * * @return mixed + * @phpstan-return T */ - public static function withTestNow($testNow = null, $callback = null); + public static function withTestNow($testNow, $callback); /** * Create a Carbon instance for yesterday. diff --git a/src/Carbon/Factory.php b/src/Carbon/Factory.php index a4a496c899..d497535f77 100644 --- a/src/Carbon/Factory.php +++ b/src/Carbon/Factory.php @@ -231,7 +231,7 @@ * You should rather use the ->settings() method. * Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants * are available for quarters, years, decade, centuries, millennia (singular and plural forms). - * @method mixed withTestNow($testNow = null, $callback = null) Temporarily sets a static date to be used within the callback. + * @method mixed withTestNow($testNow, $callback) Temporarily sets a static date to be used within the callback. * Using setTestNow to set the date, executing the callback, then * clearing the test instance. * /!\ Use this method for unit tests only. diff --git a/src/Carbon/FactoryImmutable.php b/src/Carbon/FactoryImmutable.php index 67088f21c9..715f5e7868 100644 --- a/src/Carbon/FactoryImmutable.php +++ b/src/Carbon/FactoryImmutable.php @@ -229,7 +229,7 @@ * You should rather use the ->settings() method. * Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants * are available for quarters, years, decade, centuries, millennia (singular and plural forms). - * @method mixed withTestNow($testNow = null, $callback = null) Temporarily sets a static date to be used within the callback. + * @method mixed withTestNow($testNow, $callback) Temporarily sets a static date to be used within the callback. * Using setTestNow to set the date, executing the callback, then * clearing the test instance. * /!\ Use this method for unit tests only. diff --git a/src/Carbon/Traits/Test.php b/src/Carbon/Traits/Test.php index e0c9e80683..ffd01bd4e5 100644 --- a/src/Carbon/Traits/Test.php +++ b/src/Carbon/Traits/Test.php @@ -119,12 +119,15 @@ public static function setTestNowAndTimezone($testNow = null, $tz = null) * * /!\ Use this method for unit tests only. * + * @template T + * * @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance - * @param Closure|null $callback + * @param Closure(): T $callback * * @return mixed + * @phpstan-return T */ - public static function withTestNow($testNow = null, $callback = null) + public static function withTestNow($testNow, $callback) { static::setTestNow($testNow);