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

PHPDoc on CarbonImmutable::createFromFormat incompatible with actual return type #2945

Closed
BusterNeece opened this issue Feb 12, 2024 · 2 comments · Fixed by #2946
Closed
Milestone

Comments

@BusterNeece
Copy link

Carbon 3.0.2

The phpdoc annotation here:

* @method static static createFromFormat(string $format, string $time, DateTimeZone|string|false|null $timezone = null) Parse a string into a new CarbonImmutable object according to the specified format.

is incompatible with the actual return type from the Creator trait:

/**
* Create a Carbon instance from a specific format.
*
* @param string $format Datetime format
* @param string $time
* @param DateTimeZone|string|int|null $timezone
*
* @throws InvalidFormatException
*
* @return static|null
*/
#[ReturnTypeWillChange]
public static function createFromFormat($format, $time, $timezone = null): ?self

If you have static analysis tools that trust the phpdoc annotations (i.e. phpstan), it'll throw that a comparison against null is invalid, even though the actual returned value can be null.

@kylekatarnls
Copy link
Collaborator

Thanks for report. Actually method that are declared in traits shouldn't be at all in the list of @method only methods that exist via __call should be there, it's a exclusion mistake from the doc generator.

@kylekatarnls kylekatarnls added this to the 3.1.0 milestone Feb 12, 2024
kylekatarnls added a commit that referenced this issue Feb 12, 2024
kylekatarnls added a commit that referenced this issue Feb 12, 2024
@BusterNeece
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants