From 8dc7e50d542a3bae98d9eb79b46fa91934e38ba9 Mon Sep 17 00:00:00 2001 From: Sam Lee Date: Fri, 21 Feb 2025 15:32:59 +0900 Subject: [PATCH] Set `of()` to be nullable in `ReceiptCode` --- src/ReceiptCode.php | 6 +++--- tests/ReceiptCodeTest.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ReceiptCode.php b/src/ReceiptCode.php index ce29640..2de20ee 100644 --- a/src/ReceiptCode.php +++ b/src/ReceiptCode.php @@ -82,12 +82,12 @@ public function nextCode(): string /** * Create a new instance of ReceiptCode. * - * @param string $code ReceiptCode + * @param string|null $code ReceiptCode * @return static Provides a new instance of ReceiptCode */ - public static function of(string $code): self + public static function of(?string $code = null): self { - return new self($code); + return is_null($code) ? self::make() : new self($code); } /** diff --git a/tests/ReceiptCodeTest.php b/tests/ReceiptCodeTest.php index 6206182..499ee0a 100644 --- a/tests/ReceiptCodeTest.php +++ b/tests/ReceiptCodeTest.php @@ -29,5 +29,7 @@ public function test_next_code_method() public function test_no_code() { $this->assertEquals('PO-'.date('Ymd').'-0001', ReceiptCode::make()->nextCode()); + + $this->assertEquals('PO-'.date('Ymd').'-0001', ReceiptCode::of()->nextCode()); } }