From deaefa38c7548d1ba5d0b175a9e4a4ff6eae8d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= Date: Tue, 2 Apr 2024 14:50:44 +0200 Subject: [PATCH] [BUGFIX] Simplify date range on identical years in copyright range --- src/Package/CopyrightRange.php | 4 ++++ tests/src/Package/CopyrightRangeTest.php | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Package/CopyrightRange.php b/src/Package/CopyrightRange.php index 246f0b6..e2e765b 100644 --- a/src/Package/CopyrightRange.php +++ b/src/Package/CopyrightRange.php @@ -58,6 +58,10 @@ public static function since(int $year): self public function __toString(): string { + if ($this->from === $this->to) { + return (string) $this->to; + } + if (null !== $this->from && null !== $this->to) { return sprintf('%d-%d', $this->from, $this->to); } diff --git a/tests/src/Package/CopyrightRangeTest.php b/tests/src/Package/CopyrightRangeTest.php index bad8d64..e2bb935 100644 --- a/tests/src/Package/CopyrightRangeTest.php +++ b/tests/src/Package/CopyrightRangeTest.php @@ -89,6 +89,14 @@ public function sinceUsesGivenYear(): void self::assertSame('since 2021', (string) $subject); } + #[Framework\Attributes\Test] + public function stringRepresentationDoesNotShowRangeOnIdenticalStartAndEndYear(): void + { + $subject = Src\Package\CopyrightRange::from(2024, 2024); + + self::assertSame('2024', (string) $subject); + } + private static function getCurrentYear(): int { return (int) date('Y');