You can see that even though Carbon::next and CarbonInterface::next both have return type hint as static, the @method CarbonInterface next(int|string $modifier = null) in Week trait (used by both Carbon and CarbonImmutable) is taking priority causing these false positives.
I'm not sure whether the correct fix is to drop the use of the @method docblocks, or change the return type hint from CarbonInterface to static, or something else.
Let me know if you have any more questions or need more info, happy to help where I can!
Hello,
I encountered an issue with the following code:
Carbon version: 3.6.0
PHP version: 8.2
When running PHPStan (1.11.5) on level 5, I expected to get:
But I actually get:
But if I make the following change to
src/Carbon/Traits/Week.php
:Then I get:
Alternatively, if I make the following change to
src/Carbon/Traits/Week.php
:Then I also get:
You can see that even though
Carbon::next
andCarbonInterface::next
both have return type hint asstatic
, the@method CarbonInterface next(int|string $modifier = null)
inWeek
trait (used by bothCarbon
andCarbonImmutable
) is taking priority causing these false positives.I'm not sure whether the correct fix is to drop the use of the
@method
docblocks, or change the return type hint fromCarbonInterface
tostatic
, or something else.Let me know if you have any more questions or need more info, happy to help where I can!