Add TDate template parameter to DatePeriod stubs#11728
Open
alies-dev wants to merge 3 commits intovimeo:masterfrom
Open
Add TDate template parameter to DatePeriod stubs#11728alies-dev wants to merge 3 commits intovimeo:masterfrom
alies-dev wants to merge 3 commits intovimeo:masterfrom
Conversation
The DatePeriod stub only had a `Start` template for constructor overload resolution, with `@implements IteratorAggregate<int, DateTimeInterface>` hardcoded. This caused TooManyTemplateParams when codebases targeting both PHPStan and Psalm used `DatePeriod<DateTime, DateTime>` in PHPDocs. Add a `TDate of DateTimeInterface` template parameter to all three DatePeriod stubs (PHP <8.0, 8.0-8.1, 8.2+) and use `@psalm-this-out` on the constructor to bind TDate based on the Start parameter. This aligns with PHPStorm stubs and preserves concrete DateTimeInterface subtypes through iteration. Fixes vimeo#11727
- Test DateTime start binds TDate correctly (PHP 8.2) - Test getIterator() return type for DateTimeImmutable start - Test getIterator() return type for ISO string start
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #11727
TDate of DateTimeInterfacetemplate parameter to all threeDatePeriodstubs (PHP <8.0, 8.0-8.1, 8.2+)@psalm-this-outon the constructor to bindTDatebased on theStartparameter (Start is string ? DateTime : Start)@implementsto useTDateinstead of hardcodedDateTimeInterfacegetIterator()return type from conditional toIterator<int, TDate>(PHP 8.0+)This aligns with PHPStorm stubs (used by PHPStan) and resolves
TooManyTemplateParamswhen codebases useDatePeriod<DateTime, DateTime>in PHPDocs for cross-tool compatibility.