Remove null
from parse
and rawParse
return types
#2931
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When doing some static analysis on a partial test of migrating my Laravel application to Laravel 11 + Carbon 3, I noticed that PHPStan (level max) reported nullability warnings on all calls related to
Carbon::parse
, that were previously not there. This is due to the fact that the v2 docblock usesstatic
(withoutnull
) as return type:Carbon/src/Carbon/Traits/Creator.php
Lines 205 to 219 in 0c6fd10
Diving a little further into the method (and it's near-equivalent 3.x counterpart), I'm unsure why
null
has been added as possible return type. Given that all tests seem to be running still fine after enforcing non-nullability and the old docblock already stated the expected output to be non-null, I think sticking with a non-null output type should be the way to go for the 3.x version. Moreover, looking at the method bodies, I see little possibility fornull
to be an actual output.This has the benefits of being much easier to handle both practically and statically within application, without requiring careful thinking about possible
null
values.Furthermore, I've altered the
rawParse
signature to usestatic
rather thanself
, given that looks more accurate, specific and in line with theparse
method.