briannesbitt / Carbon

A simple PHP API extension for DateTime.
https://carbon.nesbot.com/
MIT License
16.47k stars 1.28k forks source link

Psalm reports MissingDependency on CarbonPeriod #3037

Open juliangums opened 3 weeks ago

juliangums commented 3 weeks ago

Hello,

I encountered an issue with the following code:

$days = Carbon::parse($start)->toPeriod(Carbon::today(), '1 day');

or

$days = CarbonPeriod::create($startDate, '1 day', $endDate);

Carbon version: latest

PHP version: latest

The code works as expected but running static analysis with Psalm, it tells me:

psalm: MissingDependency: Carbon\CarbonPeriod depends on class or interface carbon\dateperiodbase that does not exist

Any idea why this happens? I would submit a PR if anyone can point me in the right direction, but don't actually know where to start.

Thanks!

kylekatarnls commented 3 weeks ago

Hello,

You can add files to your projects if Psalm is unable to detect them. It sounds it's not able to see what's in lazy folder:

<file name="vendor/nesbot/carbon/lazy/Carbon/UnprotectedDatePeriod.php" />
<file name="vendor/nesbot/carbon/lazy/Carbon/TranslatorStrongType.php" />
<file name="vendor/nesbot/carbon/lazy/Carbon/MessageFormatter/MessageFormatterMapperStrongType.php" />

If you can find a way so that we expose it at library level so that we can make a change and have projects using Psalm to inherit it, I would gladly merge.

Thanks.