Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 622bf5b

Browse files
fix phpstan
1 parent 6369152 commit 622bf5b

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

‎src/Annotations/Input/InputDateFormat.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,25 @@ public function match(mixed $value, DataCollection $collection, InputValueContex
3030
return is_string($value) || is_numeric($value);
3131
}
3232

33-
34-
3533
/**
3634
* @throws DateInvalidTimeZoneException
3735
*/
3836
public function resolve(mixed $value, DataCollection $collection, InputValueContext $context): string|DateTime
3937
{
40-
$timezone = $this->timezone ? new DateTimeZone($this->timezone) : null;
41-
$types = $collection->getTypes();
42-
if (!$types || count($types) !== 1) {
43-
$dateTime = DateTime::createFromFormat($this->inputFormat, (string)$value, $timezone);
44-
return $dateTime !== false ? $dateTime->format($this->outFormat) : (string)$value;
45-
}
4638

47-
$className = current($types)->className;
39+
$timezone = $this->timezone ? new DateTimeZone($this->timezone) : null;
40+
$className = current($collection->getTypes())->className;
4841

4942
if (!$this->outFormat
50-
&& in_array($className, [DateTime::class, DateTimeImmutable::class], true)
43+
&& is_subclass_of($className, DateTimeInterface::class)
5144
&& method_exists($className, 'createFromFormat')
45+
&& count($collection->getTypes()) === 1
5246
) {
5347
return $className::createFromFormat($this->inputFormat, (string)$value, $timezone);
5448
}
5549

5650
$dateTime = DateTime::createFromFormat($this->inputFormat, (string)$value, $timezone);
5751
return $dateTime !== false ? $dateTime->format($this->outFormat) : (string)$value;
52+
5853
}
5954
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /