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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ print ReceiptCode::of(prefix: 'CT')->nextCode();
### Location Code

```php
print Location::of(warehouse: 'AUK', rack: 'R3', shelf: 'S32')->locationCode();
print Location::of(['warehouse' => 'AUK', 'rack' => 'R3', 'shelf' => 'S32')->locationCode();
print Location::of(warehouse: 'AUK', rack: 'R3', shelf: 'S32'); //` Stringable` supported
print LocationCode::of(warehouse: 'AUK', rack: 'R3', shelf: 'S32')->locationCode();
print LocationCode::of(['warehouse' => 'AUK', 'rack' => 'R3', 'shelf' => 'S32')->locationCode();
print LocationCode::of(warehouse: 'AUK', rack: 'R3', shelf: 'S32'); //` Stringable` supported
//=> AUK-R3-S32
```

Expand Down
10 changes: 5 additions & 5 deletions src/Location.php → src/LocationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @since 2025-02-24
*/
class Location implements Stringable
class LocationCode implements Stringable
{
/**
* Code representing the product’s storage location
Expand Down Expand Up @@ -65,7 +65,7 @@ private function __construct(
*
* @return string The method returns the location code
*
* @example print Location::of(warehouse: 'AUK', rack: 'R3', shelf: 'S32')->locationCode();
* @example print LocationCode::of(warehouse: 'AUK', rack: 'R3', shelf: 'S32')->locationCode();
*/
public function locationCode(): string
{
Expand Down Expand Up @@ -113,12 +113,12 @@ public static function of(
}

/**
* Get the string representation of the location.
* Get the string representation of the location code.
*
* @return string The magic method returns the location code
*
* @example print Location::of(warehouse: 'A1') => 'A1'
* @example print Location::of(warehouse: 'A1', rack: 'B3') => 'A1-B3'
* @example print LocationCode::of(warehouse: 'A1') => 'A1'
* @example print LocationCode::of(warehouse: 'A1', rack: 'B3') => 'A1-B3'
*/
public function __toString(): string
{
Expand Down
30 changes: 15 additions & 15 deletions tests/LocationTest.php → tests/LocationCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

namespace Cable8mm\GoodCode\Tests;

use Cable8mm\GoodCode\Location;
use Cable8mm\GoodCode\LocationCode;
use PHPUnit\Framework\TestCase;

class LocationTest extends TestCase
class LocationCodeTest extends TestCase
{
public function test_full_location_code()
{
$this->assertEquals('AUK-R3-S32', Location::of(
$this->assertEquals('AUK-R3-S32', LocationCode::of(
warehouse: 'AUK',
rack: 'R3',
shelf: 'S32'
)->locationCode());

$this->assertEquals('AUK-R3-S32', Location::of([
$this->assertEquals('AUK-R3-S32', LocationCode::of([
'warehouse' => 'AUK',
'rack' => 'R3',
'shelf' => 'S32',
Expand All @@ -24,37 +24,37 @@ public function test_full_location_code()

public function test_location_code_without_warehouse()
{
$this->assertEquals('R3-S32', Location::of(
$this->assertEquals('R3-S32', LocationCode::of(
rack: 'R3',
shelf: 'S32'
)->locationCode());

$this->assertEquals('R3-S32', Location::of([
$this->assertEquals('R3-S32', LocationCode::of([
'rack' => 'R3',
'shelf' => 'S32',
])->locationCode());
}

public function test_location_code_without_shelf()
{
$this->assertEquals('AUK-R3', Location::of(
$this->assertEquals('AUK-R3', LocationCode::of(
warehouse: 'AUK',
rack: 'R3'
)->locationCode());

$this->assertEquals('AUK-R3', Location::of([
$this->assertEquals('AUK-R3', LocationCode::of([
'warehouse' => 'AUK',
'rack' => 'R3',
])->locationCode());
}

public function test_location_code_with_only_warehouse()
{
$this->assertEquals('AUK', Location::of(
$this->assertEquals('AUK', LocationCode::of(
warehouse: 'AUK'
)->locationCode());

$this->assertEquals('AUK', Location::of([
$this->assertEquals('AUK', LocationCode::of([
'warehouse' => 'AUK',
])->locationCode());
}
Expand All @@ -63,7 +63,7 @@ public function test_location_code_with_only_rack_excepted()
{
$this->expectException(\InvalidArgumentException::class);

Location::of([
LocationCode::of([
'rack2' => 'R3',
]);
}
Expand All @@ -72,7 +72,7 @@ public function test_location_code_with_only_shelf_excepted()
{
$this->expectException(\InvalidArgumentException::class);

Location::of([
LocationCode::of([
'shelf2' => 'S32',
]);
}
Expand All @@ -81,18 +81,18 @@ public function test_location_code_with_empty()
{
$this->expectException(\InvalidArgumentException::class);

Location::of();
LocationCode::of();
}

public function test_location_code_to_string()
{
$this->assertEquals('AUK-R3-S32', (string) Location::of(
$this->assertEquals('AUK-R3-S32', (string) LocationCode::of(
warehouse: 'AUK',
rack: 'R3',
shelf: 'S32'
));

$this->assertEquals('AUK-R3-S32', (string) Location::of([
$this->assertEquals('AUK-R3-S32', (string) LocationCode::of([
'warehouse' => 'AUK',
'rack' => 'R3',
'shelf' => 'S32',
Expand Down