Skip to content

Commit

Permalink
Merge pull request #2931 from jnoordsij/non-null-parse
Browse files Browse the repository at this point in the history
Remove `null` from `parse` and `rawParse` return types
  • Loading branch information
kylekatarnls authored Jan 31, 2024
2 parents 9bff7c1 + 6754af9 commit 7ae1c6f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ parameters:
message: '#^Call to an undefined method Carbon\\Carbon::[a-zA-Z]+Of[a-zA-Z]+\(\)\.$#'
paths:
- tests/Carbon/SettersTest.php
-
message: "#^Property Carbon\\\\Carbon\\:\\:\\$month \\(int\\) does not accept Carbon\\\\Month\\:\\:February\\.$#"
paths:
- tests/Carbon/SettersTest.php
-
message: '#^Access to an undefined property Carbon\\CarbonImmutable::\$[a-zA-Z]+\.$#'
paths:
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/CarbonInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3389,7 +3389,7 @@ public function ordinal(string $key, ?string $period = null): string;
*
* @throws InvalidFormatException
*/
public static function parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null): ?static;
public static function parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null): static;

/**
* Create a carbon instance from a localized string (in French, Japanese, Arabic, etc.).
Expand Down Expand Up @@ -3479,7 +3479,7 @@ public function rawFormat(string $format): string;
*
* @throws InvalidFormatException
*/
public static function rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null);
public static function rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null): static;

/**
* Call native PHP DateTime/DateTimeImmutable sub() method.
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@
* and recurrences). Throw an exception for invalid format, but otherwise return null.
* @method void mixin(object|string $mixin) Mix another object into the class.
* @method Carbon now(DateTimeZone|string|int|null $timezone = null) Get a Carbon instance for the current date and time.
* @method ?Carbon parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* @method Carbon parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* This is an alias for the constructor that allows better fluent syntax
* as it allows you to do Carbon::parse('Monday next week')->fn() rather
* than (new Carbon('Monday next week'))->fn().
* @method Carbon parseFromLocale(string $time, ?string $locale = null, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a localized string (in French, Japanese, Arabic, etc.).
* @method string pluralUnit(string $unit) Returns standardized plural of a given singular/plural unit name (in English).
* @method ?Carbon rawCreateFromFormat(string $format, string $time, $timezone = null) Create a Carbon instance from a specific format.
* @method ?Carbon rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* @method Carbon rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* This is an alias for the constructor that allows better fluent syntax
* as it allows you to do Carbon::parse('Monday next week')->fn() rather
* than (new Carbon('Monday next week'))->fn().
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/FactoryImmutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@
* Always return a new instance. Parse only strings and only these likely to be dates (skip intervals
* and recurrences). Throw an exception for invalid format, but otherwise return null.
* @method void mixin(object|string $mixin) Mix another object into the class.
* @method ?CarbonImmutable parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* @method CarbonImmutable parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* This is an alias for the constructor that allows better fluent syntax
* as it allows you to do Carbon::parse('Monday next week')->fn() rather
* than (new Carbon('Monday next week'))->fn().
* @method CarbonImmutable parseFromLocale(string $time, ?string $locale = null, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a localized string (in French, Japanese, Arabic, etc.).
* @method string pluralUnit(string $unit) Returns standardized plural of a given singular/plural unit name (in English).
* @method ?CarbonImmutable rawCreateFromFormat(string $format, string $time, $timezone = null) Create a Carbon instance from a specific format.
* @method ?CarbonImmutable rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* @method CarbonImmutable rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) Create a carbon instance from a string.
* This is an alias for the constructor that allows better fluent syntax
* as it allows you to do Carbon::parse('Monday next week')->fn() rather
* than (new Carbon('Monday next week'))->fn().
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Traits/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function instance(DateTimeInterface $date): static
public static function rawParse(
DateTimeInterface|WeekDay|Month|string|int|float|null $time,
DateTimeZone|string|int|null $timezone = null,
): ?self {
): static {
if ($time instanceof DateTimeInterface) {
return static::instance($time);
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public static function rawParse(
public static function parse(
DateTimeInterface|WeekDay|Month|string|int|float|null $time,
DateTimeZone|string|int|null $timezone = null,
): ?static {
): static {
$function = static::$parseFunction;

if (!$function) {
Expand Down

0 comments on commit 7ae1c6f

Please sign in to comment.