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()); } }