diff --git a/src/Carbon/CarbonInterface.php b/src/Carbon/CarbonInterface.php index 16bc3761e4..ecd1442b8a 100644 --- a/src/Carbon/CarbonInterface.php +++ b/src/Carbon/CarbonInterface.php @@ -3146,6 +3146,8 @@ public function lte(DateTimeInterface|string $date): bool; /** * Register a custom macro. * + * Pass null macro to remove it. + * * @example * ``` * $userSettings = [ @@ -3157,13 +3159,8 @@ public function lte(DateTimeInterface|string $date): bool; * }); * echo Carbon::yesterday()->hours(11)->userFormat(); * ``` - * - * @param string $name - * @param object|callable $macro - * - * @return void */ - public static function macro(string $name, callable|object $macro): void; + public static function macro(string $name, callable|object|null $macro): void; /** * Make a Carbon instance from given variable if possible. diff --git a/src/Carbon/CarbonInterval.php b/src/Carbon/CarbonInterval.php index 162ea79835..ae075bc596 100644 --- a/src/Carbon/CarbonInterval.php +++ b/src/Carbon/CarbonInterval.php @@ -1469,6 +1469,8 @@ public function isEmpty(): bool /** * Register a custom macro. * + * Pass null macro to remove it. + * * @example * ``` * CarbonInterval::macro('twice', function () { @@ -1476,13 +1478,8 @@ public function isEmpty(): bool * }); * echo CarbonInterval::hours(2)->twice(); * ``` - * - * @param string $name - * @param object|callable $macro - * - * @return void */ - public static function macro(string $name, $macro): void + public static function macro(string $name, object|callable|null $macro): void { static::$macros[$name] = $macro; } diff --git a/src/Carbon/CarbonPeriod.php b/src/Carbon/CarbonPeriod.php index 81d70cec9e..d089b4fe44 100644 --- a/src/Carbon/CarbonPeriod.php +++ b/src/Carbon/CarbonPeriod.php @@ -514,6 +514,8 @@ private static function makeInterval(mixed $input): ?CarbonInterval /** * Register a custom macro. * + * Pass null macro to remove it. + * * @example * ``` * CarbonPeriod::macro('middle', function () { @@ -521,13 +523,8 @@ private static function makeInterval(mixed $input): ?CarbonInterval * }); * echo CarbonPeriod::since('2011-05-12')->until('2011-06-03')->middle(); * ``` - * - * @param string $name - * @param object|callable $macro - * - * @return void */ - public static function macro(string $name, $macro): void + public static function macro(string $name, object|callable|null $macro): void { static::$macros[$name] = $macro; } diff --git a/src/Carbon/Factory.php b/src/Carbon/Factory.php index a7492e3c8e..49f24897da 100644 --- a/src/Carbon/Factory.php +++ b/src/Carbon/Factory.php @@ -305,19 +305,21 @@ public function getHumanDiffOptions(): int /** * Register a custom macro. * + * Pass null macro to remove it. + * * @example * ``` * $userSettings = [ * 'locale' => 'pt', * 'timezone' => 'America/Sao_Paulo', * ]; - * Carbon::macro('userFormat', function () use ($userSettings) { + * $factory->macro('userFormat', function () use ($userSettings) { * return $this->copy()->locale($userSettings['locale'])->tz($userSettings['timezone'])->calendar(); * }); - * echo Carbon::yesterday()->hours(11)->userFormat(); + * echo $factory->yesterday()->hours(11)->userFormat(); * ``` */ - public function macro(string $name, object|callable $macro): void + public function macro(string $name, object|callable|null $macro): void { $macros = $this->getSettings()['macros'] ?? []; $macros[$name] = $macro; diff --git a/src/Carbon/Traits/Macro.php b/src/Carbon/Traits/Macro.php index 33fd5c8f18..dfe7b1d9c7 100644 --- a/src/Carbon/Traits/Macro.php +++ b/src/Carbon/Traits/Macro.php @@ -39,12 +39,9 @@ trait Macro * echo Carbon::yesterday()->hours(11)->userFormat(); * ``` * - * @param string $name - * @param object|callable $macro - * - * @return void + * Pass null macro to remove it. */ - public static function macro(string $name, object|callable $macro): void + public static function macro(string $name, object|callable|null $macro): void { FactoryImmutable::getDefaultInstance()->macro($name, $macro); }