Import classes instead of using FQNs

This commit is contained in:
Jérôme Gamez
2025-09-29 23:57:09 +02:00
parent ff31026046
commit 48c449b37e
+5 -4
View File
@@ -6,6 +6,7 @@ namespace Beste\Clock;
use Beste\Clock; use Beste\Clock;
use DateTimeImmutable; use DateTimeImmutable;
use InvalidArgumentException;
use Psr\Clock\ClockInterface; use Psr\Clock\ClockInterface;
final class WrappingClock implements Clock final class WrappingClock implements Clock
@@ -24,11 +25,11 @@ final class WrappingClock implements Clock
} }
if (!method_exists($clock, 'now')) { if (!method_exists($clock, 'now')) {
throw new \InvalidArgumentException('$clock must implement StellaMaris\Clock\ClockInterface or have a now() method'); throw new InvalidArgumentException('$clock must implement StellaMaris\Clock\ClockInterface or have a now() method');
} }
if (!($clock->now() instanceof DateTimeImmutable)) { if (!($clock->now() instanceof DateTimeImmutable)) {
throw new \InvalidArgumentException('$clock->now() must return a DateTimeImmutable'); throw new InvalidArgumentException('$clock->now() must return a DateTimeImmutable');
} }
$wrappedClock = new class($clock) implements ClockInterface { $wrappedClock = new class($clock) implements ClockInterface {
@@ -39,13 +40,13 @@ final class WrappingClock implements Clock
$this->clock = $clock; $this->clock = $clock;
} }
public function now(): \DateTimeImmutable public function now(): DateTimeImmutable
{ {
assert(method_exists($this->clock, 'now')); assert(method_exists($this->clock, 'now'));
$now = $this->clock->now(); $now = $this->clock->now();
assert($now instanceof \DateTimeImmutable); assert($now instanceof DateTimeImmutable);
return $now; return $now;
} }