Skip to content

Commit

Permalink
Allow only callable or null for macro value
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Feb 5, 2024
1 parent 27a6558 commit 8a67f56
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
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

0 comments on commit 8a67f56

Please sign in to comment.