Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow only callable or null for macro value #2937

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Carbon/CarbonInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ public function isEmpty(): bool
* echo CarbonInterval::hours(2)->twice();
* ```
*/
public static function macro(string $name, object|callable|null $macro): void
public static function macro(string $name, ?callable $macro): void
{
static::$macros[$name] = $macro;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/CarbonPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ private static function makeInterval(mixed $input): ?CarbonInterval
* echo CarbonPeriod::since('2011-05-12')->until('2011-06-03')->middle();
* ```
*/
public static function macro(string $name, object|callable|null $macro): void
public static function macro(string $name, ?callable $macro): void
{
static::$macros[$name] = $macro;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function getHumanDiffOptions(): int
* echo $factory->yesterday()->hours(11)->userFormat();
* ```
*/
public function macro(string $name, object|callable|null $macro): void
public function macro(string $name, ?callable $macro): void
{
$macros = $this->getSettings()['macros'] ?? [];
$macros[$name] = $macro;
Expand Down Expand Up @@ -375,7 +375,7 @@ public function hasMacro(string $name): bool
/**
* Get the raw callable macro registered globally for a given name.
*/
public function getMacro(string $name): object|callable|null
public function getMacro(string $name): ?callable
{
return $this->getSettings()['macros'][$name] ?? null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Carbon/Traits/Macro.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ trait Macro
/**
* Register a custom macro.
*
* Pass null macro to remove it.
*
* @example
* ```
* $userSettings = [
Expand All @@ -38,10 +40,8 @@ trait Macro
* });
* echo Carbon::yesterday()->hours(11)->userFormat();
* ```
*
* Pass null macro to remove it.
*/
public static function macro(string $name, object|callable|null $macro): void
public static function macro(string $name, ?callable $macro): void
{
FactoryImmutable::getDefaultInstance()->macro($name, $macro);
}
Expand Down
Loading