-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add stub for DatePeriod #8312
Add stub for DatePeriod #8312
Conversation
I don't think that's possible unfortunately, and the only way I can think of to do it would be to add a template, which would make all other iterators more annoying to deal with. |
Per this comment it looks like we might need to have it implement |
Unfortunately, looks like I can't use a conditional |
I found these snippets: https://psalm.dev/r/f606edbe51<?php
/**
* @psalm-immutable
*
* @template-covariant Start of string|DateTimeInterface
* @implements (Start is string ? Traversable<int, DateTime> : Traversable<int, Start>)
*/
class DatePeriod implements Traversable
{
const EXCLUDE_START_DATE = 1;
/**
* @param Start $start
* @param (Start is string ? 0|self::EXCLUDE_START_DATE : DateInterval) $interval
* @param (Start is string ? never : DateTimeInterface|positive-int) $end
* @param (Start is string ? never : 0|self::EXCLUDE_START_DATE) $options
*/
public function __construct($start, $interval = 0, $end = 1, $options = 0) {}
}
https://psalm.dev/r/46f7c9b9b4<?php
/**
* @psalm-immutable
*
* @template-covariant Start of string|DateTimeInterface
* @implements Traversable<int, (Start is string ? DateTime : Start)>
*/
class DatePeriod implements Traversable
{
const EXCLUDE_START_DATE = 1;
/**
* @param Start $start
* @param (Start is string ? 0|self::EXCLUDE_START_DATE : DateInterval) $interval
* @param (Start is string ? never : DateTimeInterface|positive-int) $end
* @param (Start is string ? never : 0|self::EXCLUDE_START_DATE) $options
*/
public function __construct($start, $interval = 0, $end = 1, $options = 0) {}
}
$period = new DatePeriod("R4/2012-07-01T00:00:00Z/P7D");
foreach ($period as $dt) {
echo $dt->format("Y-m-d");
}
|
@fluffycondor It looks like you must have branched from your fork's 4.x branch, which is quite a bit behind. Could you rebase on the current 4.x? I think that should fix the test-with-real-projects PHPUnit test. |
a36e1cc
to
462ce71
Compare
Thanks! |
I wrote them in a wrong way in vimeo#8312, so they are rewritten now as @AndrolGenhald advised in vimeo#8327
I wrote them in a wrong way in vimeo#8312, so they are rewritten now as @AndrolGenhald advised in vimeo#8327
Fixes #5954
Actually I'd like to mark the returned Iterator as a non-empty one, it always yields at least one value (and 50 and 63 lines in the test actually should be non-nullable).
But I don't know how to do that :)