From a9d42cffa77b80737b3048c9a7683667b56fd089 Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Mon, 23 Oct 2023 10:30:19 -0400 Subject: [PATCH] Updates to Clock Component (#32) --- .../Component/Clock/ClockInterface.php | 20 ------------------- src/SonsOfPHP/Component/Clock/FixedClock.php | 3 ++- src/SonsOfPHP/Component/Clock/SystemClock.php | 4 +++- .../Component/Clock/Tests/FixedClockTest.php | 2 +- .../Component/Clock/Tests/SystemClockTest.php | 2 +- src/SonsOfPHP/Component/Clock/composer.json | 5 +++-- 6 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 src/SonsOfPHP/Component/Clock/ClockInterface.php diff --git a/src/SonsOfPHP/Component/Clock/ClockInterface.php b/src/SonsOfPHP/Component/Clock/ClockInterface.php deleted file mode 100644 index 6b2f0843..00000000 --- a/src/SonsOfPHP/Component/Clock/ClockInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -interface ClockInterface -{ - /** - * Returns a DateTimeInterface. - */ - public function now(): \DateTimeInterface; -} diff --git a/src/SonsOfPHP/Component/Clock/FixedClock.php b/src/SonsOfPHP/Component/Clock/FixedClock.php index c5332d06..e78dab0b 100644 --- a/src/SonsOfPHP/Component/Clock/FixedClock.php +++ b/src/SonsOfPHP/Component/Clock/FixedClock.php @@ -5,6 +5,7 @@ namespace SonsOfPHP\Component\Clock; use SonsOfPHP\Component\Clock\Exception\ClockException; +use Psr\Clock\ClockInterface; /** * Fixed Clock. @@ -30,7 +31,7 @@ public function __toString(): string return 'FixedClock[' . $this->zone->getName() . ']'; } - public function now(): \DateTimeInterface + public function now(): \DateTimeImmutable { return $this->time; } diff --git a/src/SonsOfPHP/Component/Clock/SystemClock.php b/src/SonsOfPHP/Component/Clock/SystemClock.php index 8f39363a..a6a9a458 100644 --- a/src/SonsOfPHP/Component/Clock/SystemClock.php +++ b/src/SonsOfPHP/Component/Clock/SystemClock.php @@ -4,6 +4,8 @@ namespace SonsOfPHP\Component\Clock; +use Psr\Clock\ClockInterface; + /** * System Clock. * @@ -23,7 +25,7 @@ public function __toString(): string return 'SystemClock[' . $this->zone->getName() . ']'; } - public function now(): \DateTimeInterface + public function now(): \DateTimeImmutable { return new \DateTimeImmutable('now', $this->zone); } diff --git a/src/SonsOfPHP/Component/Clock/Tests/FixedClockTest.php b/src/SonsOfPHP/Component/Clock/Tests/FixedClockTest.php index 2b1c1f63..bfbbeb95 100644 --- a/src/SonsOfPHP/Component/Clock/Tests/FixedClockTest.php +++ b/src/SonsOfPHP/Component/Clock/Tests/FixedClockTest.php @@ -5,7 +5,7 @@ namespace SonsOfPHP\Component\Clock\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Clock\ClockInterface; +use Psr\Clock\ClockInterface; use SonsOfPHP\Component\Clock\Exception\ClockException; use SonsOfPHP\Component\Clock\FixedClock; diff --git a/src/SonsOfPHP/Component/Clock/Tests/SystemClockTest.php b/src/SonsOfPHP/Component/Clock/Tests/SystemClockTest.php index a2b47999..985067f6 100644 --- a/src/SonsOfPHP/Component/Clock/Tests/SystemClockTest.php +++ b/src/SonsOfPHP/Component/Clock/Tests/SystemClockTest.php @@ -5,7 +5,7 @@ namespace SonsOfPHP\Component\Clock\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Clock\ClockInterface; +use Psr\Clock\ClockInterface; use SonsOfPHP\Component\Clock\SystemClock; /** diff --git a/src/SonsOfPHP/Component/Clock/composer.json b/src/SonsOfPHP/Component/Clock/composer.json index 6827abf6..511c9311 100644 --- a/src/SonsOfPHP/Component/Clock/composer.json +++ b/src/SonsOfPHP/Component/Clock/composer.json @@ -41,7 +41,8 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1" + "php": ">=8.1", + "psr/clock": "^1.0" }, "extra": { "sort-packages": true, @@ -59,4 +60,4 @@ "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" } ] -} \ No newline at end of file +}