Carbon: PHPStan complains about Carbon::create suddenly returning false?
Hello,
I encountered an issue with the following code:
Carbon::setTestNow(Carbon::create(2017, 4, 4, 13, 58));
Carbon version: 2.36.1 PHP version: 7.4
PHPStan complains everywhere I use the code snippet above:
24 Parameter #1 $testNow of static method Carbon\Carbon::setTestNow()
expects Carbon\Carbon|Closure|string|null, Carbon\Carbon|false given.
This has been introduced in https://github.com/briannesbitt/Carbon/pull/1916.
I don’t get why create
can 1) return a date, 2) throw an exception or 3) return false? It’s not in the interface, but only in the implementation.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (4 by maintainers)
Commits related to this issue
- Fix #2135 Allow setTestNow() to take `false` — committed to kylekatarnls/Carbon by kylekatarnls 4 years ago
- Merge pull request #2137 from kylekatarnls/feature/issue-2135-accept-false-in-setTestNow Fix #2135 Allow `setTestNow()` to take `false` — committed to briannesbitt/Carbon by kylekatarnls 4 years ago
@i-bajrai
createStrict()
will finally be implemented in 2.49.0Release of 2.37 is planned for Tuesday.
Meanwhile you can set
"nesbot/carbon": "2.x-dev"
in your composer.json to test the next version.Interface and other PHPDoc for
create()
method has been fixed (added|false
as it’s the actual return type) andsetTestNow()
now accepts silentlyfalse
(equivalent tonull
=> removing the testNow reference).IMO, this is the only thing we should do about that for the 2.x version.