Skip to content

Commit 22b0df6

Browse files
committed
fix: Some PHPStan errors
1 parent b70871e commit 22b0df6

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

system/I18n/TimeTrait.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,17 @@ public function subYears(int $years)
870870
*/
871871
public function clamp(DateTimeInterface|self|string $start, DateTimeInterface|self|string $end): static
872872
{
873-
$start = $start instanceof DateTimeInterface ? $start : new static($start, $this->timezone, $this->locale);
874-
$end = $end instanceof DateTimeInterface ? $end : new static($end, $this->timezone, $this->locale);
873+
if ($start instanceof DateTimeInterface && ! $start instanceof self) {
874+
$start = static::createFromInstance($start, $this->locale);
875+
} elseif (is_string($start)) {
876+
$start = new static($start, $this->getTimezone(), $this->locale);
877+
}
878+
879+
if ($end instanceof DateTimeInterface && ! $end instanceof self) {
880+
$end = static::createFromInstance($end, $this->locale);
881+
} elseif (is_string($end)) {
882+
$end = new static($end, $this->getTimezone(), $this->locale);
883+
}
875884

876885
if ($end->isBefore($start)) {
877886
throw I18nException::forInvalidClampRange($start->toDateTimeString(), $end->toDateTimeString());

0 commit comments

Comments
 (0)