Lines 100.00% 1 / 1
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Iso8601DateTime 100.00% 1 / 1 100.00% 1 / 1 1 100.00% 1 / 1
 __toString 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace HushHush;
6
7/**
8 * A \DateTime that formats itself as ATOM/ISO-8601 when cast to string.
9 *
10 * AuditLogApi::queryAuditLogRequest() declares from/to's openApiType as the
11 * literal string 'string', not '\DateTime', so
12 * ObjectSerializer::toQueryValue() never takes its DateTime-formatting
13 * branch and instead bare-casts whatever it's handed — plain \DateTime has
14 * no __toString(), so that throws. Still passing a real \DateTime (rather
15 * than a pre-formatted string) keeps the value's type compatible with the
16 * generated method's own `DateTime|null` docblock.
17 */
18final class Iso8601DateTime extends \DateTime implements \Stringable
19{
20    public function __toString(): string
21    {
22        return $this->format(\DateTime::ATOM);
23    }
24}