You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php/** * @return ($value is null ? null : \DateTimeImmutable) */functionconvertDateTime(null|\DateTimeInterface|string$value): ?\DateTimeImmutable
{
if (null === $value || $valueinstanceof \DateTimeImmutable) {
return$value;
}
if ($valueinstanceof \DateTimeInterface) {
return \DateTimeImmutable::createFromInterface($value);
}
$res = \DateTimeImmutable::createFromFormat(\DATE_ATOM, $value);
if (false === $res) {
thrownew \InvalidArgumentException(sprintf('The value %s is not a valid date time string based on the format %s', $value, \DATE_ATOM));
}
return$res;
}
Psalm output (using commit 79ab7e2):
ERROR: PossiblyInvalidCast - 16:61 - DateTimeInterface cannot be cast to string
ERROR: PossiblyInvalidArgument - 16:61 - Argument 2 of DateTimeImmutable::createFromFormat expects string, but possibly different type TGeneratedFromParam0:fn-convertdatetime as DateTimeInterface|string provided
ERROR: PossiblyInvalidArgument - 18:124 - Argument 2 of sprintf expects float|int|object{__tostring()}|string, but possibly different type TGeneratedFromParam0:fn-convertdatetime as DateTimeInterface|string provided
Example
https://psalm.dev/r/8a642de112
Explanation
Since I am checking for all relevant types before line 16,
$value
can only bestring
at this point. Psalm doesn't seem to agree.Am I missing something?
The text was updated successfully, but these errors were encountered: