mirror of
https://github.com/beste/clock.git
synced 2026-08-17 17:47:13 +00:00
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.0",
|
"php": "^8.0",
|
||||||
"psr/clock": "^1.0"
|
"stella-maris/clock": "^0.1.6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpstan/extension-installer": "^1.2",
|
"phpstan/extension-installer": "^1.2",
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Beste;
|
namespace Beste;
|
||||||
|
|
||||||
use Psr\Clock\ClockInterface;
|
use StellaMaris\Clock\ClockInterface;
|
||||||
|
|
||||||
interface Clock extends ClockInterface
|
interface Clock extends ClockInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace Beste\Clock;
|
|||||||
use Beste\Clock;
|
use Beste\Clock;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use Psr\Clock\ClockInterface;
|
use StellaMaris\Clock\ClockInterface;
|
||||||
|
|
||||||
final class FrozenClock implements Clock
|
final class FrozenClock implements Clock
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace Beste\Clock;
|
|||||||
|
|
||||||
use Beste\Clock;
|
use Beste\Clock;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Psr\Clock\ClockInterface;
|
use StellaMaris\Clock\ClockInterface;
|
||||||
|
|
||||||
final class MinuteClock implements Clock
|
final class MinuteClock implements Clock
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ namespace Beste\Clock;
|
|||||||
|
|
||||||
use Beste\Clock;
|
use Beste\Clock;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use InvalidArgumentException;
|
use StellaMaris\Clock\ClockInterface;
|
||||||
use Psr\Clock\ClockInterface;
|
|
||||||
|
|
||||||
final class WrappingClock implements Clock
|
final class WrappingClock implements Clock
|
||||||
{
|
{
|
||||||
@@ -25,11 +24,11 @@ final class WrappingClock implements Clock
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!method_exists($clock, 'now')) {
|
if (!method_exists($clock, 'now')) {
|
||||||
throw new InvalidArgumentException('$clock must implement '.ClockInterface::class.' 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 {
|
||||||
@@ -40,13 +39,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace Beste\Clock\Tests;
|
|||||||
use Beste\Clock\FrozenClock;
|
use Beste\Clock\FrozenClock;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Clock\ClockInterface;
|
use StellaMaris\Clock\ClockInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace Beste\Clock\Tests;
|
|||||||
use Beste\Clock\MinuteClock;
|
use Beste\Clock\MinuteClock;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Clock\ClockInterface;
|
use StellaMaris\Clock\ClockInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
|||||||
Reference in New Issue
Block a user