Skip to content

Conversation

Alban-io
Copy link
Contributor

Resolve phpstan/phpstan#5953
Previous PR : #762

@ondrejmirtes
Copy link
Member

Restore the original stub with ?int etc. and rebase on top of master, the nullable union bound should now work: 1d8b2eb

@Alban-io Alban-io force-pushed the date-period-dynamic-return-type branch from 89d17c7 to 1166c34 Compare January 30, 2022 10:00
@Alban-io
Copy link
Contributor Author

I rebase but some tests failed

@ondrejmirtes
Copy link
Member

DatePeriod::getRecurrences() was added in PHP 7.2. You can run the test only on newer PHP versions if you put the yield in a condition. It's already done many times in NodeScopeResolverTest.

]);
}

return new GenericObjectType(DatePeriod::class, [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic isn't sufficient. You also need to test scenarios like when the third argument is mixed or DateTimeInterface|int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a more explicit version

@Alban-io Alban-io force-pushed the date-period-dynamic-return-type branch 2 times, most recently from f3e0636 to f0ad821 Compare January 30, 2022 12:53
* @template TEnd of ?DateTimeInterface
* @template TRecurrences of ?int
*/
class DatePeriod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing - DatePeriod needs to be added here in the config:

skipCheckGenericClasses: []

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simiarly to what was done here: phpstan/phpstan-doctrine@8061e5f

@Alban-io Alban-io force-pushed the date-period-dynamic-return-type branch 2 times, most recently from f705fee to fad3849 Compare January 30, 2022 15:31
@Alban-io Alban-io force-pushed the date-period-dynamic-return-type branch from fad3849 to b1950fa Compare January 30, 2022 15:45
@Alban-io Alban-io force-pushed the date-period-dynamic-return-type branch from b1950fa to 1676836 Compare January 30, 2022 15:59
@Alban-io Alban-io requested a review from ondrejmirtes January 30, 2022 16:25
@ondrejmirtes ondrejmirtes merged commit 855a4ab into phpstan:master Jan 30, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@Alban-io
Copy link
Contributor Author

Thank you for your support

It was interesting to discover how PHPStan works

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 this pull request may close these issues.

DatePeriod::getEndDate can be null
3 participants