diff --git a/README.md b/README.md index 9d885d6..1652402 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ We have provided the API Documentation on the web. For more information, please - [x] Option Good code parser(No code, it matched by name) - [x] Receipt code parser - [x] Location code parser -- [x] Box code parser +- [x] SKU parser ## Install @@ -213,15 +213,12 @@ print LocationCode::of(warehouse: 'AUK', rack: 'R3', shelf: 'S32'); //` Stringab //=> AUK-R3-S32 ``` -### Box Code +### SKU ```php -print BoxCode::of(code: 123, prefix: 'PO'); //=> PO123 -print BoxCode::of([ - 'code' => 123, 'prefix' => 'PO' - ])->boxCode(); //=> PO123 -print BoxCode::of(123)->boxCode(); //=> 123 -print BoxCode::of(123, prefix: 'PO'); //=> PO123 +print Sku::of(code: 123, prefix: 'PO'); //=> PO123 +print Sku::of(123); //=> 123 +print Sku::of(123, prefix: 'PO'); //=> PO123 ``` ## Formatting diff --git a/src/BoxCode.php b/src/Sku.php similarity index 57% rename from src/BoxCode.php rename to src/Sku.php index 7018526..570a091 100644 --- a/src/BoxCode.php +++ b/src/Sku.php @@ -5,24 +5,24 @@ use Stringable; /** - * This class represents a box code identified by code and prefix. The box code is generated from these properties. + * This class represents a SKU identified by code and prefix. The SKU is generated from these properties. * * @author Samgu Lee * * @since 2025-02-24 */ -class BoxCode implements Stringable +class Sku implements Stringable { /** - * Code representing the box + * Code representing the SKU * * @example BO123 */ - private string $boxCode; + private string $sku; private function __construct( /** - * Box code + * The code for the sku * * @example 123 */ @@ -34,27 +34,26 @@ private function __construct( */ private ?string $prefix = null ) { - $this->boxCode = $prefix.$code; + $this->sku = $prefix.$code; } /** - * Get the box code. + * Get the SKU. * - * @return string The method returns the box code + * @return string The method returns the SKU * - * @example print BoxCode::of(123, prefix: 'BO')->boxCode(); => 'BO123' - * @example print BoxCode::of(123, prefix: 'BO'); => 'BO123' + * @example print Sku::of(123, prefix: 'BO'); => 'BO123' */ - public function boxCode(): string + public function sku(): string { - return $this->boxCode; + return $this->sku; } /** - * Create a new box code instance. + * Create a new SKU instance. * - * @param string|int $code The box code - * @param string|null $prefix Prefix for the box code + * @param string|int $code The SKU + * @param string|null $prefix Prefix for the SKU * @return self Provides fluent interface * * @throws \InvalidArgumentException @@ -83,15 +82,15 @@ public static function of( } /** - * Get the string representation of the box code. + * Get the string representation of the SKU. * - * @return string The magic method returns the box code + * @return string The magic method returns the SKU * - * @example print BoxCode::of('1') => 'A1' - * @example print BoxCode::of('1', prefix: 'BO') => 'BO1' + * @example print Sku::of('1') => 'A1' + * @example print Sku::of('1', prefix: 'BO') => 'BO1' */ public function __toString(): string { - return $this->boxCode; + return $this->sku; } } diff --git a/tests/BoxCodeTest.php b/tests/BoxCodeTest.php deleted file mode 100644 index 84294e4..0000000 --- a/tests/BoxCodeTest.php +++ /dev/null @@ -1,42 +0,0 @@ -assertEquals('PO123', BoxCode::of( - 123, - prefix: 'PO' - )->boxCode()); - - $this->assertEquals('PO123', BoxCode::of([ - 'code' => 123, - 'prefix' => 'PO', - ])); - } - - public function test_box_code_without_prefix() - { - $this->assertEquals('123', BoxCode::of( - 123 - )->boxCode()); - - $this->assertEquals('123', BoxCode::of([ - 'code' => 123, - ])); - } - - public function test_location_code_with_empty() - { - $this->expectException(\InvalidArgumentException::class); - - BoxCode::of([ - 'wrong' => 'key', - ]); - } -} diff --git a/tests/SkuTest.php b/tests/SkuTest.php new file mode 100644 index 0000000..28f94c7 --- /dev/null +++ b/tests/SkuTest.php @@ -0,0 +1,33 @@ +assertEquals('PO123', Sku::of([ + 'code' => 123, + 'prefix' => 'PO', + ])); + } + + public function test_sku_without_prefix() + { + $this->assertEquals('123', Sku::of([ + 'code' => 123, + ])); + } + + public function test_sku_with_wrong_code() + { + $this->expectException(\InvalidArgumentException::class); + + Sku::of([ + 'wrong' => 'key', + ]); + } +}