Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
39 changes: 19 additions & 20 deletions src/BoxCode.php → src/Sku.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cable8mm@gmail.com>
*
* @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
*/
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
42 changes: 0 additions & 42 deletions tests/BoxCodeTest.php

This file was deleted.

33 changes: 33 additions & 0 deletions tests/SkuTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Cable8mm\GoodCode\Tests;

use Cable8mm\GoodCode\Sku;
use PHPUnit\Framework\TestCase;

class SkuTest extends TestCase
{
public function test_full_sku()
{
$this->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',
]);
}
}