Skip to content

Add TDate template parameter to DatePeriod stubs#11728

Open
alies-dev wants to merge 3 commits intovimeo:masterfrom
alies-dev:fix/dateperiod-tdate-template
Open

Add TDate template parameter to DatePeriod stubs#11728
alies-dev wants to merge 3 commits intovimeo:masterfrom
alies-dev:fix/dateperiod-tdate-template

Conversation

@alies-dev
Copy link
Contributor

@alies-dev alies-dev commented Mar 13, 2026

Fixes #11727

  • Add TDate of DateTimeInterface template parameter to all three DatePeriod stubs (PHP <8.0, 8.0-8.1, 8.2+)
  • Use @psalm-this-out on the constructor to bind TDate based on the Start parameter (Start is string ? DateTime : Start)
  • Update @implements to use TDate instead of hardcoded DateTimeInterface
  • Simplify getIterator() return type from conditional to Iterator<int, TDate> (PHP 8.0+)

This aligns with PHPStorm stubs (used by PHPStan) and resolves TooManyTemplateParams when codebases use DatePeriod<DateTime, DateTime> in PHPDocs for cross-tool compatibility.

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
@alies-dev alies-dev changed the base branch from 6.x to master March 13, 2026 22:47
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 stub missing TDate template: iteration type not preserved

1 participant