From e4519ee63c05d34cfae4a18290652a3878376245 Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 21:38:53 +0200 Subject: [PATCH 01/12] Create custom parameter objects for Coupons --- src/Enums/CouponStatus.php | 86 ++++++++++++++++++++ src/Enums/Direction.php | 51 ++++++++++++ src/Exceptions/InvalidDirectionException.php | 13 +++ src/Repositories/CouponRepository.php | 12 ++- tests/Unit/Enums/CouponStatusTest.php | 41 ++++++++++ tests/Unit/Enums/DirectionTest.php | 42 ++++++++++ 6 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 src/Enums/CouponStatus.php create mode 100644 src/Enums/Direction.php create mode 100644 src/Exceptions/InvalidDirectionException.php create mode 100644 tests/Unit/Enums/CouponStatusTest.php create mode 100644 tests/Unit/Enums/DirectionTest.php diff --git a/src/Enums/CouponStatus.php b/src/Enums/CouponStatus.php new file mode 100644 index 0000000..f6aec42 --- /dev/null +++ b/src/Enums/CouponStatus.php @@ -0,0 +1,86 @@ + 'Open', + 'S' => 'Redeemed', + 'D' => 'Denied', + 'E' => 'Expired', + ]; + + private array $statuses = []; + + public function __toString(): string + { + return implode(',', $this->statuses); + } + + public static function default(): static + { + return new static(); + } + + public static function make(): static + { + return new static(); + } + + public function open(): static + { + $this->statuses[] = 'O'; + + return $this; + } + + public function withoutOpen(): static + { + $this->statuses[] = '-O'; + + return $this; + } + + public function redeemed(): static + { + $this->statuses[] = 'S'; + + return $this; + } + + public function withoutRedeemed(): static + { + $this->statuses[] = '-S'; + + return $this; + } + + public function denied(): static + { + $this->statuses[] = 'D'; + + return $this; + } + + public function withoutDenied(): static + { + $this->statuses[] = '-D'; + + return $this; + } + + public function expired(): static + { + $this->statuses[] = 'E'; + + return $this; + } + + public function withoutExpired(): static + { + $this->statuses[] = '-E'; + + return $this; + } +} diff --git a/src/Enums/Direction.php b/src/Enums/Direction.php new file mode 100644 index 0000000..5a38d8d --- /dev/null +++ b/src/Enums/Direction.php @@ -0,0 +1,51 @@ +direction = $direction; + } + + public function __toString(): string + { + return $this->direction; + } + + public function in(): static + { + $this->direction = static::IN; + + return $this; + } + + public function out(): static + { + $this->direction = static::OUT; + + return $this; + } + + public static function default(): static + { + return new static(static::IN); + } + + public static function make(?string $direction = null): static + { + return $direction ? new static($direction) : static::default(); + } +} diff --git a/src/Exceptions/InvalidDirectionException.php b/src/Exceptions/InvalidDirectionException.php new file mode 100644 index 0000000..c602f91 --- /dev/null +++ b/src/Exceptions/InvalidDirectionException.php @@ -0,0 +1,13 @@ + $direction, - 'status' => param($statuses), + 'direction' => $direction ? (string) $direction : (string) Direction::default(), + 'status' => $status ? (string) $status : (string) CouponStatus::default(), ]); $response = $this->gateway->get($uri); diff --git a/tests/Unit/Enums/CouponStatusTest.php b/tests/Unit/Enums/CouponStatusTest.php new file mode 100644 index 0000000..6cf320d --- /dev/null +++ b/tests/Unit/Enums/CouponStatusTest.php @@ -0,0 +1,41 @@ +assertEquals('', (string) $status); + } + + public function testItCreatesASingleStatus(): void + { + $status = CouponStatus::make()->open(); + + $this->assertEquals('O', (string) $status); + } + + public function testItCreatesMultipleStatuses(): void + { + $status = CouponStatus::make()->open()->denied()->expired(); + + $this->assertEquals('O,D,E', (string) $status); + } + + public function testItCanExcludeStatuses(): void + { + $status = CouponStatus::make()->open()->withoutDenied()->withoutExpired(); + + $this->assertEquals('O,-D,-E', (string) $status); + } +} diff --git a/tests/Unit/Enums/DirectionTest.php b/tests/Unit/Enums/DirectionTest.php new file mode 100644 index 0000000..03b201b --- /dev/null +++ b/tests/Unit/Enums/DirectionTest.php @@ -0,0 +1,42 @@ +assertEquals(Direction::IN, (string) $direction); + } + + public function testItCreatesADirection(): void + { + $direction = Direction::make()->out(); + + $this->assertEquals(Direction::OUT, (string) $direction); + } + + public function testDirectionCanBeChanged(): void + { + $direction = Direction::make()->in()->out(); + + $this->assertEquals(Direction::OUT, (string) $direction); + } + + public function testItThrowsOnInvalidDirection(): void + { + $this->expectException(InvalidDirectionException::class); + + Direction::make('left'); + } +} From 8e2024cefbef03b7ef502f0500f79b8cb8301ea4 Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 21:44:43 +0200 Subject: [PATCH 02/12] Use Direction parameter for Feedback --- src/Repositories/FeedbackRepository.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Repositories/FeedbackRepository.php b/src/Repositories/FeedbackRepository.php index 1853a80..da8e8b1 100644 --- a/src/Repositories/FeedbackRepository.php +++ b/src/Repositories/FeedbackRepository.php @@ -3,6 +3,7 @@ namespace Davesweb\BrinklinkApi\Repositories; use function Davesweb\uri; +use Davesweb\BrinklinkApi\Enums\Direction; use Davesweb\BrinklinkApi\ValueObjects\Feedback; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Exceptions\NotFoundException; @@ -10,17 +11,14 @@ class FeedbackRepository extends BaseRepository { - public const DIRECTION_IN = 'in'; - public const DIRECTION_OUT = 'out'; - public function __construct(BricklinkGateway $gateway, FeedbackTransformer $transformer) { parent::__construct($gateway, $transformer); } - public function index(string $direction = self::DIRECTION_IN): iterable + public function index(?Direction $direction = null): iterable { - $uri = uri('feedback', [], ['direction' => $direction]); + $uri = uri('feedback', [], ['direction' => $direction ? (string) $direction : Direction::default()]); $response = $this->gateway->get($uri); From dfe0c1c88f21c5094a11f8b4c608e2779bd0eda4 Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 22:19:25 +0200 Subject: [PATCH 03/12] Add parameter objects for inventories --- src/Enums/Id.php | 47 +++++++ src/Enums/InventoryStatus.php | 116 ++++++++++++++++ src/Enums/ItemType.php | 161 +++++++++++++++++++++++ src/Repositories/FeedbackRepository.php | 2 +- src/Repositories/InventoryRepository.php | 20 +-- tests/Unit/Enums/IdTest.php | 48 +++++++ tests/Unit/Enums/InventoryStatusTest.php | 41 ++++++ tests/Unit/Enums/ItemTypeTest.php | 41 ++++++ 8 files changed, 466 insertions(+), 10 deletions(-) create mode 100644 src/Enums/Id.php create mode 100644 src/Enums/InventoryStatus.php create mode 100644 src/Enums/ItemType.php create mode 100644 tests/Unit/Enums/IdTest.php create mode 100644 tests/Unit/Enums/InventoryStatusTest.php create mode 100644 tests/Unit/Enums/ItemTypeTest.php diff --git a/src/Enums/Id.php b/src/Enums/Id.php new file mode 100644 index 0000000..0aeb59b --- /dev/null +++ b/src/Enums/Id.php @@ -0,0 +1,47 @@ +ids); + } + + public static function default(): static + { + return new static(); + } + + public static function make(array|int|null $with = null): static + { + return $with ? (new static())->with($with) : new static(); + } + + public function with(int|array $id): static + { + if (is_array($id)) { + $this->ids = array_merge($this->ids, $id); + } else { + $this->ids[] = $id; + } + + return $this; + } + + public function without(int|array $id): static + { + if (is_array($id)) { + $this->ids = array_merge($this->ids, array_map(function (int $id) { + return '-' . $id; + }, $id)); + } else { + $this->ids[] = '-' . $id; + } + + return $this; + } +} diff --git a/src/Enums/InventoryStatus.php b/src/Enums/InventoryStatus.php new file mode 100644 index 0000000..7670417 --- /dev/null +++ b/src/Enums/InventoryStatus.php @@ -0,0 +1,116 @@ + 'Available', + 'S' => 'In stockroom A', + 'B' => 'In stockroom B', + 'C' => 'In stockroom C', + 'N' => 'Unavailable', + 'R' => 'Reserved', + ]; + + private array $statuses = []; + + public function __toString(): string + { + return implode(',', $this->statuses); + } + + public static function default(): static + { + return new static(); + } + + public static function make(): static + { + return new static(); + } + + public function available(): static + { + $this->statuses[] = 'Y'; + + return $this; + } + + public function withoutAvailable(): static + { + $this->statuses[] = '-Y'; + + return $this; + } + + public function inStockroomA(): static + { + $this->statuses[] = 'S'; + + return $this; + } + + public function withoutStockroomA(): static + { + $this->statuses[] = '-S'; + + return $this; + } + + public function inStockroomB(): static + { + $this->statuses[] = 'B'; + + return $this; + } + + public function withoutStockroomB(): static + { + $this->statuses[] = '-B'; + + return $this; + } + + public function inStockroomC(): static + { + $this->statuses[] = 'C'; + + return $this; + } + + public function withoutStockroomC(): static + { + $this->statuses[] = '-C'; + + return $this; + } + + public function unavailable(): static + { + $this->statuses[] = 'N'; + + return $this; + } + + public function withoutUnavailable(): static + { + $this->statuses[] = '-N'; + + return $this; + } + + public function reserved(): static + { + $this->statuses[] = 'R'; + + return $this; + } + + public function withoutReserved(): static + { + $this->statuses[] = '-R'; + + return $this; + } +} diff --git a/src/Enums/ItemType.php b/src/Enums/ItemType.php new file mode 100644 index 0000000..06d7f64 --- /dev/null +++ b/src/Enums/ItemType.php @@ -0,0 +1,161 @@ +types); + } + + public static function default(): static + { + return new static(); + } + + public static function make(): static + { + return new static(); + } + + public function minifig(): static + { + $this->types[] = 'MINIFIG'; + + return $this; + } + + public function withoutMinifig(): static + { + $this->types[] = '-MINIFIG'; + + return $this; + } + + public function part(): static + { + $this->types[] = 'PART'; + + return $this; + } + + public function withoutPart(): static + { + $this->types[] = '-PART'; + + return $this; + } + + public function set(): static + { + $this->types[] = 'SET'; + + return $this; + } + + public function withoutSet(): static + { + $this->types[] = '-SET'; + + return $this; + } + + public function book(): static + { + $this->types[] = 'BOOK'; + + return $this; + } + + public function withoutBook(): static + { + $this->types[] = '-BOOK'; + + return $this; + } + + public function gear(): static + { + $this->types[] = 'GEAR'; + + return $this; + } + + public function withoutGear(): static + { + $this->types[] = '-GEAR'; + + return $this; + } + + public function catelog(): static + { + $this->types[] = 'CATALOG'; + + return $this; + } + + public function withoutCatelog(): static + { + $this->types[] = '-CATALOG'; + + return $this; + } + + public function instructions(): static + { + $this->types[] = 'INSTRUCTION'; + + return $this; + } + + public function withoutInstructions(): static + { + $this->types[] = '-INSTRUCTION'; + + return $this; + } + + public function unsortedLot(): static + { + $this->types[] = 'UNSORTED_LOT'; + + return $this; + } + + public function withoutUnsortedLot(): static + { + $this->types[] = '-UNSORTED_LOT'; + + return $this; + } + + public function originalBox(): static + { + $this->types[] = 'ORIGINAL_BOX'; + + return $this; + } + + public function withoutOriginalBox(): static + { + $this->types[] = '-ORIGINAL_BOX'; + + return $this; + } +} diff --git a/src/Repositories/FeedbackRepository.php b/src/Repositories/FeedbackRepository.php index da8e8b1..abb6565 100644 --- a/src/Repositories/FeedbackRepository.php +++ b/src/Repositories/FeedbackRepository.php @@ -18,7 +18,7 @@ public function __construct(BricklinkGateway $gateway, FeedbackTransformer $tran public function index(?Direction $direction = null): iterable { - $uri = uri('feedback', [], ['direction' => $direction ? (string) $direction : Direction::default()]); + $uri = uri('feedback', [], ['direction' => $direction ? (string) $direction : (string) Direction::default()]); $response = $this->gateway->get($uri); diff --git a/src/Repositories/InventoryRepository.php b/src/Repositories/InventoryRepository.php index 7c27c51..6ac86a0 100644 --- a/src/Repositories/InventoryRepository.php +++ b/src/Repositories/InventoryRepository.php @@ -3,7 +3,9 @@ namespace Davesweb\BrinklinkApi\Repositories; use function Davesweb\uri; -use function Davesweb\param; +use Davesweb\BrinklinkApi\Enums\Id; +use Davesweb\BrinklinkApi\Enums\ItemType; +use Davesweb\BrinklinkApi\Enums\InventoryStatus; use Davesweb\BrinklinkApi\ValueObjects\Inventory; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Exceptions\NotFoundException; @@ -17,16 +19,16 @@ public function __construct(BricklinkGateway $gateway, InventoryTransformer $tra } public function index( - string|array|null $itemTypes = null, - string|array|null $statuses = null, - int|array|null $categoryIds = null, - int|array|null $colorIds = null + ?ItemType $itemTypes = null, + ?InventoryStatus $status = null, + ?Id $categoryIds = null, + ?Id $colorIds = null ): iterable { $uri = uri('inventories', [], [ - 'item_types' => param($itemTypes), - 'status' => param($statuses), - 'category_id' => param($categoryIds), - 'color_id' => param($colorIds), + 'item_types' => $itemTypes ? (string) $itemTypes : (string) ItemType::default(), + 'status' => $status ? (string) $status : (string) InventoryStatus::default(), + 'category_id' => $categoryIds ? (string) $categoryIds : (string) Id::default(), + 'color_id' => $colorIds ? (string) $colorIds : (string) Id::default(), ]); $response = $this->gateway->get($uri); diff --git a/tests/Unit/Enums/IdTest.php b/tests/Unit/Enums/IdTest.php new file mode 100644 index 0000000..843addb --- /dev/null +++ b/tests/Unit/Enums/IdTest.php @@ -0,0 +1,48 @@ +assertEquals('', (string) $ids); + } + + public function testItCreatesASingleId(): void + { + $ids = Id::make()->with(1); + + $this->assertEquals('1', (string) $ids); + } + + public function testItCreatesMultipleIds(): void + { + $ids = Id::make()->with([1, 2, 3]); + + $this->assertEquals('1,2,3', (string) $ids); + } + + public function testItCanExcludeId(): void + { + $ids = Id::make()->with(1)->without(2); + + $this->assertEquals('1,-2', (string) $ids); + } + + public function testItCanExcludeMultipleIds(): void + { + $ids = Id::make()->with(1)->without([2, 3, 4]); + + $this->assertEquals('1,-2,-3,-4', (string) $ids); + } +} diff --git a/tests/Unit/Enums/InventoryStatusTest.php b/tests/Unit/Enums/InventoryStatusTest.php new file mode 100644 index 0000000..f7a948a --- /dev/null +++ b/tests/Unit/Enums/InventoryStatusTest.php @@ -0,0 +1,41 @@ +assertEquals('', (string) $status); + } + + public function testItCreatesASingleStatus(): void + { + $status = InventoryStatus::make()->available(); + + $this->assertEquals('Y', (string) $status); + } + + public function testItCreatesMultipleStatuses(): void + { + $status = InventoryStatus::make()->available()->inStockroomA()->inStockroomB(); + + $this->assertEquals('Y,S,B', (string) $status); + } + + public function testItCanExcludeStatuses(): void + { + $status = InventoryStatus::make()->available()->withoutReserved()->withoutUnavailable(); + + $this->assertEquals('Y,-R,-N', (string) $status); + } +} diff --git a/tests/Unit/Enums/ItemTypeTest.php b/tests/Unit/Enums/ItemTypeTest.php new file mode 100644 index 0000000..fade44a --- /dev/null +++ b/tests/Unit/Enums/ItemTypeTest.php @@ -0,0 +1,41 @@ +assertEquals('', (string) $status); + } + + public function testItCreatesASingleItemType(): void + { + $status = ItemType::make()->part(); + + $this->assertEquals('PART', (string) $status); + } + + public function testItCreatesMultipleItemTypes(): void + { + $status = ItemType::make()->part()->minifig()->set(); + + $this->assertEquals('PART,MINIFIG,SET', (string) $status); + } + + public function testItCanExcludeItemTypes(): void + { + $status = ItemType::make()->PART()->withoutGear()->withoutBook(); + + $this->assertEquals('PART,-GEAR,-BOOK', (string) $status); + } +} From 31480501ec034b80da826895c811f9655f676adb Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 22:30:39 +0200 Subject: [PATCH 04/12] Add ItemType parameter object to item repository --- src/Repositories/ItemRepository.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Repositories/ItemRepository.php b/src/Repositories/ItemRepository.php index cf23664..bba269d 100644 --- a/src/Repositories/ItemRepository.php +++ b/src/Repositories/ItemRepository.php @@ -3,6 +3,7 @@ namespace Davesweb\BrinklinkApi\Repositories; use function Davesweb\uri; +use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\ValueObjects\Item; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Exceptions\NotFoundException; @@ -23,10 +24,10 @@ public function __construct( $this->knownColorTransformer = $knownColorTransformer; } - public function find(string $number, string $type = 'part'): ?Item + public function find(string $number, ?ItemType $type = null): ?Item { $uri = uri('/items/{type}/{number}', [ - 'type' => $type, + 'type' => $type ? (string) $type : ItemType::default(), 'number' => $number, ]); @@ -42,7 +43,7 @@ public function find(string $number, string $type = 'part'): ?Item return $item; } - public function findOrFail(string $number, string $type = 'part'): Item + public function findOrFail(string $number, ?ItemType $type = null): Item { return $this->find($number, $type) ?? throw NotFoundException::forId($number); } @@ -72,10 +73,10 @@ public function findOrFailItemImage(Item $item, int $colorId = 1): Item return $this->findItemImage($item, $colorId) ?? throw NotFoundException::forId($item->number); } - public function knownColors(string $number, string $type = 'part'): iterable + public function knownColors(string $number, ?ItemType $type = null): iterable { $uri = uri('/items/{type}/{number}/colors', [ - 'type' => $type, + 'type' => $type ? (string) $type : ItemType::default(), 'number' => $number, ]); From 240e9f318f18daef7d4dd376f61eebaf9d9653d5 Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 22:32:26 +0200 Subject: [PATCH 05/12] Add ItemType parameter object to mapping repository --- src/Repositories/MappingRepository.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Repositories/MappingRepository.php b/src/Repositories/MappingRepository.php index 497510c..7ffc423 100644 --- a/src/Repositories/MappingRepository.php +++ b/src/Repositories/MappingRepository.php @@ -3,6 +3,7 @@ namespace Davesweb\BrinklinkApi\Repositories; use function Davesweb\uri; +use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\ValueObjects\Mapping; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Transformers\MappingTransformer; @@ -14,10 +15,10 @@ public function __construct(BricklinkGateway $gateway, MappingTransformer $trans parent::__construct($gateway, $transformer); } - public function getElementId(string $number, string $type = 'part', ?int $colorId = null): ?Mapping + public function getElementId(string $number, ?ItemType $type = null, ?int $colorId = null): ?Mapping { $uri = uri('/item_mapping/{type}/{number}', [ - 'type' => strtoupper($type), + 'type' => $type ? (string) $type : ItemType::default(), 'number' => $number, ], [ 'color_id' => $colorId, From 6530a2a0bdcd8eda28c6a1afb76382e652b8f1b0 Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 23:00:38 +0200 Subject: [PATCH 06/12] Add order status and order payment status parameter objects --- src/Enums/OrderPaymentStatus.php | 136 +++++++++++ src/Enums/OrderStatus.php | 256 ++++++++++++++++++++ src/Repositories/OrderRepository.php | 18 +- tests/Feature/OrderTest.php | 6 +- tests/Unit/Enums/OrderPaymentStatusTest.php | 41 ++++ tests/Unit/Enums/OrderStatusTest.php | 41 ++++ 6 files changed, 488 insertions(+), 10 deletions(-) create mode 100644 src/Enums/OrderPaymentStatus.php create mode 100644 src/Enums/OrderStatus.php create mode 100644 tests/Unit/Enums/OrderPaymentStatusTest.php create mode 100644 tests/Unit/Enums/OrderStatusTest.php diff --git a/src/Enums/OrderPaymentStatus.php b/src/Enums/OrderPaymentStatus.php new file mode 100644 index 0000000..5dc99f6 --- /dev/null +++ b/src/Enums/OrderPaymentStatus.php @@ -0,0 +1,136 @@ +statuses); + } + + public static function default(): static + { + return new static(); + } + + public static function make(): static + { + return new static(); + } + + public function none(): static + { + $this->statuses[] = 'None'; + + return $this; + } + + public function withoutNone(): static + { + $this->statuses[] = '-None'; + + return $this; + } + + public function sent(): static + { + $this->statuses[] = 'Sent'; + + return $this; + } + + public function withoutSent(): static + { + $this->statuses[] = '-Sent'; + + return $this; + } + + public function received(): static + { + $this->statuses[] = 'Received'; + + return $this; + } + + public function withoutReceived(): static + { + $this->statuses[] = '-Received'; + + return $this; + } + + public function clearing(): static + { + $this->statuses[] = 'Clearing'; + + return $this; + } + + public function withoutClearing(): static + { + $this->statuses[] = '-Clearing'; + + return $this; + } + + public function returned(): static + { + $this->statuses[] = 'Returned'; + + return $this; + } + + public function withoutReturned(): static + { + $this->statuses[] = '-Returned'; + + return $this; + } + + public function bounced(): static + { + $this->statuses[] = 'Bounced'; + + return $this; + } + + public function withoutBounced(): static + { + $this->statuses[] = '-Bounced'; + + return $this; + } + + public function completed(): static + { + $this->statuses[] = 'Completed'; + + return $this; + } + + public function withoutCompleted(): static + { + $this->statuses[] = '-Completed'; + + return $this; + } +} diff --git a/src/Enums/OrderStatus.php b/src/Enums/OrderStatus.php new file mode 100644 index 0000000..4bf425d --- /dev/null +++ b/src/Enums/OrderStatus.php @@ -0,0 +1,256 @@ +statuses); + } + + public static function default(): static + { + return new static(); + } + + public static function make(): static + { + return new static(); + } + + public function pending(): static + { + $this->statuses[] = 'Pending'; + + return $this; + } + + public function withoutPending(): static + { + $this->statuses[] = '-Pending'; + + return $this; + } + + public function updated(): static + { + $this->statuses[] = 'Updated'; + + return $this; + } + + public function withoutUpdated(): static + { + $this->statuses[] = '-Updated'; + + return $this; + } + + public function processing(): static + { + $this->statuses[] = 'Processing'; + + return $this; + } + + public function withoutProcessing(): static + { + $this->statuses[] = '-Processing'; + + return $this; + } + + public function ready(): static + { + $this->statuses[] = 'Ready'; + + return $this; + } + + public function withoutReady(): static + { + $this->statuses[] = '-Ready'; + + return $this; + } + + public function paid(): static + { + $this->statuses[] = 'Paid'; + + return $this; + } + + public function withoutPaid(): static + { + $this->statuses[] = '-Paid'; + + return $this; + } + + public function packed(): static + { + $this->statuses[] = 'Packed'; + + return $this; + } + + public function withoutPacked(): static + { + $this->statuses[] = '-Packed'; + + return $this; + } + + public function shipped(): static + { + $this->statuses[] = 'Shipped'; + + return $this; + } + + public function withoutShipped(): static + { + $this->statuses[] = '-Shipped'; + + return $this; + } + + public function received(): static + { + $this->statuses[] = 'Received'; + + return $this; + } + + public function withoutReceived(): static + { + $this->statuses[] = '-Received'; + + return $this; + } + + public function completed(): static + { + $this->statuses[] = 'Completed'; + + return $this; + } + + public function withoutCompleted(): static + { + $this->statuses[] = '-Completed'; + + return $this; + } + + public function ocr(): static + { + $this->statuses[] = 'OCR'; + + return $this; + } + + public function withoutOcr(): static + { + $this->statuses[] = '-OCR'; + + return $this; + } + + public function npb(): static + { + $this->statuses[] = 'NPB'; + + return $this; + } + + public function withoutNpb(): static + { + $this->statuses[] = '-NPB'; + + return $this; + } + + public function npx(): static + { + $this->statuses[] = 'NPX'; + + return $this; + } + + public function withoutNpx(): static + { + $this->statuses[] = '-NPX'; + + return $this; + } + + public function nrs(): static + { + $this->statuses[] = 'NRS'; + + return $this; + } + + public function withoutNrs(): static + { + $this->statuses[] = '-NRS'; + + return $this; + } + + public function nss(): static + { + $this->statuses[] = 'NSS'; + + return $this; + } + + public function withoutNss(): static + { + $this->statuses[] = '-NSS'; + + return $this; + } + + public function cancelled(): static + { + $this->statuses[] = 'Cancelled'; + + return $this; + } + + public function withoutCancelled(): static + { + $this->statuses[] = '-Cancelled'; + + return $this; + } +} diff --git a/src/Repositories/OrderRepository.php b/src/Repositories/OrderRepository.php index a538914..fd456e7 100644 --- a/src/Repositories/OrderRepository.php +++ b/src/Repositories/OrderRepository.php @@ -3,8 +3,10 @@ namespace Davesweb\BrinklinkApi\Repositories; use function Davesweb\uri; -use function Davesweb\param; +use Davesweb\BrinklinkApi\Enums\Direction; +use Davesweb\BrinklinkApi\Enums\OrderStatus; use Davesweb\BrinklinkApi\ValueObjects\Order; +use Davesweb\BrinklinkApi\Enums\OrderPaymentStatus; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Exceptions\NotFoundException; use Davesweb\BrinklinkApi\Transformers\OrderTransformer; @@ -37,11 +39,11 @@ public function __construct( $this->feedbackTransformer = $feedbackTransformer; } - public function index(string $direction = self::DIRECTION_IN, string|array|null $statuses = null, bool $filed = false): iterable + public function index(?Direction $direction = null, ?OrderStatus $statuses = null, bool $filed = false): iterable { $uri = uri('orders', [], [ - 'direction' => $direction, - 'status' => param($statuses), + 'direction' => $direction ? (string) $direction : Direction::default(), + 'status' => $statuses ? (string) $statuses : OrderStatus::default(), 'filed' => $filed ? 'true' : 'false', ]); @@ -139,21 +141,21 @@ public function update(Order $order): Order return $updatedOrder; } - public function updateStatus(Order $order, string $newStatus): bool + public function updateStatus(Order $order, OrderStatus $newStatus): bool { $response = $this->gateway->put( uri('/orders/{id}/status', ['id' => $order->orderId]), - ['field' => 'status', 'value' => $newStatus], + ['field' => 'status', 'value' => (string) $newStatus], ); return $response->isSuccessful(); } - public function updatePaymentStatus(Order $order, string $newStatus): bool + public function updatePaymentStatus(Order $order, OrderPaymentStatus $newStatus): bool { $response = $this->gateway->put( uri('/orders/{id}/status', ['id' => $order->orderId]), - ['field' => 'payment_status', 'value' => $newStatus], + ['field' => 'payment_status', 'value' => (string) $newStatus], ); return $response->isSuccessful(); diff --git a/tests/Feature/OrderTest.php b/tests/Feature/OrderTest.php index d03fbaa..62e3266 100644 --- a/tests/Feature/OrderTest.php +++ b/tests/Feature/OrderTest.php @@ -5,6 +5,7 @@ use DateTime; use Davesweb\BrinklinkApi\Tests\TestCase; use Davesweb\BrinklinkApi\BricklinkResponse; +use Davesweb\BrinklinkApi\Enums\OrderStatus; use Davesweb\BrinklinkApi\ValueObjects\Cost; use Davesweb\BrinklinkApi\ValueObjects\Item; use Davesweb\BrinklinkApi\ValueObjects\Name; @@ -15,6 +16,7 @@ use Davesweb\BrinklinkApi\ValueObjects\Feedback; use Davesweb\BrinklinkApi\ValueObjects\Shipping; use Davesweb\BrinklinkApi\ValueObjects\OrderItem; +use Davesweb\BrinklinkApi\Enums\OrderPaymentStatus; use Davesweb\BrinklinkApi\ValueObjects\OrderMessage; use Davesweb\BrinklinkApi\Exceptions\NotFoundException; use Davesweb\BrinklinkApi\Repositories\OrderRepository; @@ -152,7 +154,7 @@ public function testItUpdatesAnOrderStatus(): void $gateway = new TestBricklinkGateway($response); $repository = new OrderRepository($gateway, new OrderTransformer(), new OrderItemTransformer(), new OrderMessageTransformer(), new FeedbackTransformer()); - $result = $repository->updateStatus(new Order(orderId: 1234), 'SHIPPED'); + $result = $repository->updateStatus(new Order(orderId: 1234), OrderStatus::make()->shipped()); $this->assertTrue($result); } @@ -164,7 +166,7 @@ public function testItUpdatesAnOrderPaymentStatus(): void $gateway = new TestBricklinkGateway($response); $repository = new OrderRepository($gateway, new OrderTransformer(), new OrderItemTransformer(), new OrderMessageTransformer(), new FeedbackTransformer()); - $result = $repository->updatePaymentStatus(new Order(orderId: 1234), 'PAID'); + $result = $repository->updatePaymentStatus(new Order(orderId: 1234), OrderPaymentStatus::make()->received()); $this->assertTrue($result); } diff --git a/tests/Unit/Enums/OrderPaymentStatusTest.php b/tests/Unit/Enums/OrderPaymentStatusTest.php new file mode 100644 index 0000000..bdad311 --- /dev/null +++ b/tests/Unit/Enums/OrderPaymentStatusTest.php @@ -0,0 +1,41 @@ +assertEquals('', (string) $status); + } + + public function testItCreatesASingleStatus(): void + { + $status = OrderPaymentStatus::make()->bounced(); + + $this->assertEquals('Bounced', (string) $status); + } + + public function testItCreatesMultipleStatuses(): void + { + $status = OrderPaymentStatus::make()->bounced()->clearing()->received(); + + $this->assertEquals('Bounced,Clearing,Received', (string) $status); + } + + public function testItCanExcludeStatuses(): void + { + $status = OrderPaymentStatus::make()->bounced()->withoutClearing()->withoutNone(); + + $this->assertEquals('Bounced,-Clearing,-None', (string) $status); + } +} diff --git a/tests/Unit/Enums/OrderStatusTest.php b/tests/Unit/Enums/OrderStatusTest.php new file mode 100644 index 0000000..e8d32d2 --- /dev/null +++ b/tests/Unit/Enums/OrderStatusTest.php @@ -0,0 +1,41 @@ +assertEquals('', (string) $status); + } + + public function testItCreatesASingleStatus(): void + { + $status = OrderStatus::make()->received(); + + $this->assertEquals('Received', (string) $status); + } + + public function testItCreatesMultipleStatuses(): void + { + $status = OrderStatus::make()->received()->updated()->completed(); + + $this->assertEquals('Received,Updated,Completed', (string) $status); + } + + public function testItCanExcludeStatuses(): void + { + $status = OrderStatus::make()->received()->withoutCancelled()->withoutNpb(); + + $this->assertEquals('Received,-Cancelled,-NPB', (string) $status); + } +} From a3cb92a6837c81cdcbd7ac1d3785faa93bc9bfff Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 23:18:14 +0200 Subject: [PATCH 07/12] Add parameter objects for priceguides --- src/Enums/GuideType.php | 51 ++++++++++++++++++++ src/Enums/NewOrUsed.php | 51 ++++++++++++++++++++ src/Exceptions/InvalidGuideTypeException.php | 13 +++++ src/Exceptions/InvalidNewOrUsedException.php | 13 +++++ src/Repositories/PriceGuideRepository.php | 21 ++++---- tests/Unit/Enums/GuideTypeTest.php | 42 ++++++++++++++++ tests/Unit/Enums/NewOrUsedTest.php | 42 ++++++++++++++++ 7 files changed, 224 insertions(+), 9 deletions(-) create mode 100644 src/Enums/GuideType.php create mode 100644 src/Enums/NewOrUsed.php create mode 100644 src/Exceptions/InvalidGuideTypeException.php create mode 100644 src/Exceptions/InvalidNewOrUsedException.php create mode 100644 tests/Unit/Enums/GuideTypeTest.php create mode 100644 tests/Unit/Enums/NewOrUsedTest.php diff --git a/src/Enums/GuideType.php b/src/Enums/GuideType.php new file mode 100644 index 0000000..5afc0c7 --- /dev/null +++ b/src/Enums/GuideType.php @@ -0,0 +1,51 @@ +type = $type; + } + + public function __toString(): string + { + return $this->type; + } + + public function sold(): static + { + $this->type = static::SOLD; + + return $this; + } + + public function stock(): static + { + $this->type = static::STOCK; + + return $this; + } + + public static function default(): static + { + return new static(static::STOCK); + } + + public static function make(?string $type = null): static + { + return $type ? new static($type) : static::default(); + } +} diff --git a/src/Enums/NewOrUsed.php b/src/Enums/NewOrUsed.php new file mode 100644 index 0000000..c79fbb0 --- /dev/null +++ b/src/Enums/NewOrUsed.php @@ -0,0 +1,51 @@ +type = $type; + } + + public function __toString(): string + { + return $this->type; + } + + public function new(): static + { + $this->type = static::NEW; + + return $this; + } + + public function used(): static + { + $this->type = static::USED; + + return $this; + } + + public static function default(): static + { + return new static(static::NEW); + } + + public static function make(?string $type = null): static + { + return $type ? new static($type) : static::default(); + } +} diff --git a/src/Exceptions/InvalidGuideTypeException.php b/src/Exceptions/InvalidGuideTypeException.php new file mode 100644 index 0000000..5b17a0c --- /dev/null +++ b/src/Exceptions/InvalidGuideTypeException.php @@ -0,0 +1,13 @@ + $type, + 'type' => $type ? (string) $type : ItemType::default(), 'number' => $number, ], [ 'color_id' => $colorId, - 'guide_type' => $guideType, - 'new_or_used' => $newOrUsed, + 'guide_type' => $guideType ? (string) $guideType : (string) GuideType::default(), + 'new_or_used' => $newOrUsed ? (string) $newOrUsed : (string) NewOrUsed::default(), 'country_code' => $countryCode, 'region' => $region, 'currency_code' => $currencyCode, @@ -53,10 +56,10 @@ public function find( public function findOrFail( string $number, - string $type = 'part', + ?ItemType $type = null, ?int $colorId = null, - string $guideType = 'stock', - string $newOrUsed = 'N', + ?GuideType $guideType = null, + ?NewOrUsed $newOrUsed = null, ?string $countryCode = null, ?string $region = null, ?string $currencyCode = null, diff --git a/tests/Unit/Enums/GuideTypeTest.php b/tests/Unit/Enums/GuideTypeTest.php new file mode 100644 index 0000000..7d155a2 --- /dev/null +++ b/tests/Unit/Enums/GuideTypeTest.php @@ -0,0 +1,42 @@ +assertEquals(GuideType::STOCK, (string) $type); + } + + public function testItCreatesADirection(): void + { + $type = GuideType::make()->sold(); + + $this->assertEquals(GuideType::SOLD, (string) $type); + } + + public function testDirectionCanBeChanged(): void + { + $type = GuideType::make()->sold()->stock(); + + $this->assertEquals(GuideType::STOCK, (string) $type); + } + + public function testItThrowsOnInvalidDirection(): void + { + $this->expectException(InvalidGuideTypeException::class); + + GuideType::make('for rent'); + } +} diff --git a/tests/Unit/Enums/NewOrUsedTest.php b/tests/Unit/Enums/NewOrUsedTest.php new file mode 100644 index 0000000..0b82b18 --- /dev/null +++ b/tests/Unit/Enums/NewOrUsedTest.php @@ -0,0 +1,42 @@ +assertEquals(NewOrUsed::NEW, (string) $type); + } + + public function testItCreatesADirection(): void + { + $type = NewOrUsed::make()->used(); + + $this->assertEquals(NewOrUsed::USED, (string) $type); + } + + public function testDirectionCanBeChanged(): void + { + $type = NewOrUsed::make()->new()->used(); + + $this->assertEquals(NewOrUsed::USED, (string) $type); + } + + public function testItThrowsOnInvalidDirection(): void + { + $this->expectException(InvalidNewOrUsedException::class); + + NewOrUsed::make('rented'); + } +} From d48b7f77487876d0007e68efc51a5c851fdcc500 Mon Sep 17 00:00:00 2001 From: davesweb Date: Sun, 22 Aug 2021 23:23:06 +0200 Subject: [PATCH 08/12] Add ItemType parameter objects to subsets and supersets --- src/Repositories/SubsetRepository.php | 5 +++-- src/Repositories/SupersetRepository.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Repositories/SubsetRepository.php b/src/Repositories/SubsetRepository.php index 27f81d4..1ecfa1d 100644 --- a/src/Repositories/SubsetRepository.php +++ b/src/Repositories/SubsetRepository.php @@ -3,6 +3,7 @@ namespace Davesweb\BrinklinkApi\Repositories; use function Davesweb\uri; +use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Transformers\SubsetTransformer; @@ -15,7 +16,7 @@ public function __construct(BricklinkGateway $gateway, SubsetTransformer $transf public function index( string $number, - string $type = 'part', + ?ItemType $type = null, ?int $colorId = null, ?bool $box = null, ?bool $instruction = null, @@ -23,7 +24,7 @@ public function index( ?bool $breakSubsets = null, ): iterable { $uri = uri('/items/{type}/{number}/subsets', [ - 'type' => $type, + 'type' => $type ? (string) $type : ItemType::default(), 'number' => $number, ], [ 'color_id' => $colorId, diff --git a/src/Repositories/SupersetRepository.php b/src/Repositories/SupersetRepository.php index 3b54965..c237978 100644 --- a/src/Repositories/SupersetRepository.php +++ b/src/Repositories/SupersetRepository.php @@ -3,6 +3,7 @@ namespace Davesweb\BrinklinkApi\Repositories; use function Davesweb\uri; +use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Transformers\SupersetTransformer; @@ -13,10 +14,10 @@ public function __construct(BricklinkGateway $gateway, SupersetTransformer $tran parent::__construct($gateway, $transformer); } - public function index(string $number, string $type = 'part', ?int $colorId = null): iterable + public function index(string $number, ?ItemType $type = null, ?int $colorId = null): iterable { $uri = uri('/items/{type}/{number}/supersets', [ - 'type' => $type, + 'type' => $type ? (string) $type : ItemType::default(), 'number' => $number, 'color_id' => $colorId, ]); From fc6d4381a3a03d131e89acf759552946fc85e923 Mon Sep 17 00:00:00 2001 From: davesweb Date: Wed, 25 Aug 2021 04:29:03 +0200 Subject: [PATCH 09/12] Add helper to stringify the parameter objects --- src/Repositories/CouponRepository.php | 5 +++-- src/Repositories/InventoryRepository.php | 9 +++++---- src/Repositories/ItemRepository.php | 3 ++- src/Repositories/MappingRepository.php | 3 ++- src/Repositories/OrderRepository.php | 5 +++-- src/Repositories/PriceGuideRepository.php | 5 +++-- src/Repositories/SupersetRepository.php | 3 ++- src/helpers.php | 16 +++------------- 8 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/Repositories/CouponRepository.php b/src/Repositories/CouponRepository.php index b45b57d..b024841 100644 --- a/src/Repositories/CouponRepository.php +++ b/src/Repositories/CouponRepository.php @@ -2,6 +2,7 @@ namespace Davesweb\BrinklinkApi\Repositories; +use function Davesweb\toString; use function Davesweb\uri; use Davesweb\BrinklinkApi\Enums\Direction; use Davesweb\BrinklinkApi\Enums\CouponStatus; @@ -20,8 +21,8 @@ public function __construct(BricklinkGateway $gateway, CouponTransformer $transf public function index(?Direction $direction = null, ?CouponStatus $status = null): iterable { $uri = uri('coupons', [], [ - 'direction' => $direction ? (string) $direction : (string) Direction::default(), - 'status' => $status ? (string) $status : (string) CouponStatus::default(), + 'direction' => toString($direction, Direction::default()), + 'status' => toString($status, CouponStatus::default()), ]); $response = $this->gateway->get($uri); diff --git a/src/Repositories/InventoryRepository.php b/src/Repositories/InventoryRepository.php index 6ac86a0..983797d 100644 --- a/src/Repositories/InventoryRepository.php +++ b/src/Repositories/InventoryRepository.php @@ -2,6 +2,7 @@ namespace Davesweb\BrinklinkApi\Repositories; +use function Davesweb\toString; use function Davesweb\uri; use Davesweb\BrinklinkApi\Enums\Id; use Davesweb\BrinklinkApi\Enums\ItemType; @@ -25,10 +26,10 @@ public function index( ?Id $colorIds = null ): iterable { $uri = uri('inventories', [], [ - 'item_types' => $itemTypes ? (string) $itemTypes : (string) ItemType::default(), - 'status' => $status ? (string) $status : (string) InventoryStatus::default(), - 'category_id' => $categoryIds ? (string) $categoryIds : (string) Id::default(), - 'color_id' => $colorIds ? (string) $colorIds : (string) Id::default(), + 'item_types' => toString($itemTypes, ItemType::default()), + 'status' => toString($status, InventoryStatus::default()), + 'category_id' => toString($categoryIds, Id::default()), + 'color_id' => toString($colorIds, Id::default()), ]); $response = $this->gateway->get($uri); diff --git a/src/Repositories/ItemRepository.php b/src/Repositories/ItemRepository.php index bba269d..64b024e 100644 --- a/src/Repositories/ItemRepository.php +++ b/src/Repositories/ItemRepository.php @@ -2,6 +2,7 @@ namespace Davesweb\BrinklinkApi\Repositories; +use function Davesweb\toString; use function Davesweb\uri; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\ValueObjects\Item; @@ -27,7 +28,7 @@ public function __construct( public function find(string $number, ?ItemType $type = null): ?Item { $uri = uri('/items/{type}/{number}', [ - 'type' => $type ? (string) $type : ItemType::default(), + 'type' => toString($type, ItemType::default()), 'number' => $number, ]); diff --git a/src/Repositories/MappingRepository.php b/src/Repositories/MappingRepository.php index 7ffc423..64dbcca 100644 --- a/src/Repositories/MappingRepository.php +++ b/src/Repositories/MappingRepository.php @@ -2,6 +2,7 @@ namespace Davesweb\BrinklinkApi\Repositories; +use function Davesweb\toString; use function Davesweb\uri; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\ValueObjects\Mapping; @@ -18,7 +19,7 @@ public function __construct(BricklinkGateway $gateway, MappingTransformer $trans public function getElementId(string $number, ?ItemType $type = null, ?int $colorId = null): ?Mapping { $uri = uri('/item_mapping/{type}/{number}', [ - 'type' => $type ? (string) $type : ItemType::default(), + 'type' => toString($type, ItemType::default()), 'number' => $number, ], [ 'color_id' => $colorId, diff --git a/src/Repositories/OrderRepository.php b/src/Repositories/OrderRepository.php index fd456e7..ecb72a8 100644 --- a/src/Repositories/OrderRepository.php +++ b/src/Repositories/OrderRepository.php @@ -2,6 +2,7 @@ namespace Davesweb\BrinklinkApi\Repositories; +use function Davesweb\toString; use function Davesweb\uri; use Davesweb\BrinklinkApi\Enums\Direction; use Davesweb\BrinklinkApi\Enums\OrderStatus; @@ -42,8 +43,8 @@ public function __construct( public function index(?Direction $direction = null, ?OrderStatus $statuses = null, bool $filed = false): iterable { $uri = uri('orders', [], [ - 'direction' => $direction ? (string) $direction : Direction::default(), - 'status' => $statuses ? (string) $statuses : OrderStatus::default(), + 'direction' => toString($direction, Direction::default()), + 'status' => toString($statuses, OrderStatus::default()), 'filed' => $filed ? 'true' : 'false', ]); diff --git a/src/Repositories/PriceGuideRepository.php b/src/Repositories/PriceGuideRepository.php index 3883cc2..959716a 100644 --- a/src/Repositories/PriceGuideRepository.php +++ b/src/Repositories/PriceGuideRepository.php @@ -2,6 +2,7 @@ namespace Davesweb\BrinklinkApi\Repositories; +use function Davesweb\toString; use function Davesweb\uri; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\Enums\GuideType; @@ -34,8 +35,8 @@ public function find( 'number' => $number, ], [ 'color_id' => $colorId, - 'guide_type' => $guideType ? (string) $guideType : (string) GuideType::default(), - 'new_or_used' => $newOrUsed ? (string) $newOrUsed : (string) NewOrUsed::default(), + 'guide_type' => toString($guideType, GuideType::default()), + 'new_or_used' => toString($newOrUsed, NewOrUsed::default()), 'country_code' => $countryCode, 'region' => $region, 'currency_code' => $currencyCode, diff --git a/src/Repositories/SupersetRepository.php b/src/Repositories/SupersetRepository.php index c237978..7692f77 100644 --- a/src/Repositories/SupersetRepository.php +++ b/src/Repositories/SupersetRepository.php @@ -2,6 +2,7 @@ namespace Davesweb\BrinklinkApi\Repositories; +use function Davesweb\toString; use function Davesweb\uri; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; @@ -17,7 +18,7 @@ public function __construct(BricklinkGateway $gateway, SupersetTransformer $tran public function index(string $number, ?ItemType $type = null, ?int $colorId = null): iterable { $uri = uri('/items/{type}/{number}/supersets', [ - 'type' => $type ? (string) $type : ItemType::default(), + 'type' => toString($type, ItemType::default()), 'number' => $number, 'color_id' => $colorId, ]); diff --git a/src/helpers.php b/src/helpers.php index f4f4bce..927dbdc 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -17,19 +17,9 @@ function uri(string $uri, array $replace = [], array $params = []): string } } -if (!function_exists('param')) { - function param(mixed $values, ?string $paramName = null): ?string +if (!function_exists('toString')) { + function toString(mixed $stringable, mixed $default = null): ?string { - if (null === $values) { - return null; - } - - if (is_array($values)) { - $value = implode(',', $values); - } else { - $value = $values; - } - - return null !== $paramName ? $paramName . '=' . $value : $value; + return $stringable !== null ? (string) $stringable : ($default !== null ? (string) $default : null); } } From f18dc72671b509174b31c6c42de6db88dd1463ac Mon Sep 17 00:00:00 2001 From: davesweb Date: Wed, 25 Aug 2021 04:31:32 +0200 Subject: [PATCH 10/12] CS fixer --- src/Repositories/CouponRepository.php | 2 +- src/Repositories/InventoryRepository.php | 2 +- src/Repositories/ItemRepository.php | 2 +- src/Repositories/MappingRepository.php | 2 +- src/Repositories/OrderRepository.php | 2 +- src/Repositories/PriceGuideRepository.php | 2 +- src/Repositories/SupersetRepository.php | 2 +- src/helpers.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Repositories/CouponRepository.php b/src/Repositories/CouponRepository.php index b024841..a30ff5c 100644 --- a/src/Repositories/CouponRepository.php +++ b/src/Repositories/CouponRepository.php @@ -2,8 +2,8 @@ namespace Davesweb\BrinklinkApi\Repositories; -use function Davesweb\toString; use function Davesweb\uri; +use function Davesweb\toString; use Davesweb\BrinklinkApi\Enums\Direction; use Davesweb\BrinklinkApi\Enums\CouponStatus; use Davesweb\BrinklinkApi\ValueObjects\Coupon; diff --git a/src/Repositories/InventoryRepository.php b/src/Repositories/InventoryRepository.php index 983797d..7e6613d 100644 --- a/src/Repositories/InventoryRepository.php +++ b/src/Repositories/InventoryRepository.php @@ -2,8 +2,8 @@ namespace Davesweb\BrinklinkApi\Repositories; -use function Davesweb\toString; use function Davesweb\uri; +use function Davesweb\toString; use Davesweb\BrinklinkApi\Enums\Id; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\Enums\InventoryStatus; diff --git a/src/Repositories/ItemRepository.php b/src/Repositories/ItemRepository.php index 64b024e..22633b2 100644 --- a/src/Repositories/ItemRepository.php +++ b/src/Repositories/ItemRepository.php @@ -2,8 +2,8 @@ namespace Davesweb\BrinklinkApi\Repositories; -use function Davesweb\toString; use function Davesweb\uri; +use function Davesweb\toString; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\ValueObjects\Item; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; diff --git a/src/Repositories/MappingRepository.php b/src/Repositories/MappingRepository.php index 64dbcca..6a9af65 100644 --- a/src/Repositories/MappingRepository.php +++ b/src/Repositories/MappingRepository.php @@ -2,8 +2,8 @@ namespace Davesweb\BrinklinkApi\Repositories; -use function Davesweb\toString; use function Davesweb\uri; +use function Davesweb\toString; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\ValueObjects\Mapping; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; diff --git a/src/Repositories/OrderRepository.php b/src/Repositories/OrderRepository.php index ecb72a8..e32ab03 100644 --- a/src/Repositories/OrderRepository.php +++ b/src/Repositories/OrderRepository.php @@ -2,8 +2,8 @@ namespace Davesweb\BrinklinkApi\Repositories; -use function Davesweb\toString; use function Davesweb\uri; +use function Davesweb\toString; use Davesweb\BrinklinkApi\Enums\Direction; use Davesweb\BrinklinkApi\Enums\OrderStatus; use Davesweb\BrinklinkApi\ValueObjects\Order; diff --git a/src/Repositories/PriceGuideRepository.php b/src/Repositories/PriceGuideRepository.php index 959716a..b45af05 100644 --- a/src/Repositories/PriceGuideRepository.php +++ b/src/Repositories/PriceGuideRepository.php @@ -2,8 +2,8 @@ namespace Davesweb\BrinklinkApi\Repositories; -use function Davesweb\toString; use function Davesweb\uri; +use function Davesweb\toString; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\Enums\GuideType; use Davesweb\BrinklinkApi\Enums\NewOrUsed; diff --git a/src/Repositories/SupersetRepository.php b/src/Repositories/SupersetRepository.php index 7692f77..59824ec 100644 --- a/src/Repositories/SupersetRepository.php +++ b/src/Repositories/SupersetRepository.php @@ -2,8 +2,8 @@ namespace Davesweb\BrinklinkApi\Repositories; -use function Davesweb\toString; use function Davesweb\uri; +use function Davesweb\toString; use Davesweb\BrinklinkApi\Enums\ItemType; use Davesweb\BrinklinkApi\Contracts\BricklinkGateway; use Davesweb\BrinklinkApi\Transformers\SupersetTransformer; diff --git a/src/helpers.php b/src/helpers.php index 927dbdc..c93fdd7 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -20,6 +20,6 @@ function uri(string $uri, array $replace = [], array $params = []): string if (!function_exists('toString')) { function toString(mixed $stringable, mixed $default = null): ?string { - return $stringable !== null ? (string) $stringable : ($default !== null ? (string) $default : null); + return null !== $stringable ? (string) $stringable : (null !== $default ? (string) $default : null); } } From 20db660afcf453412e4fa92b23be1f55a981e67e Mon Sep 17 00:00:00 2001 From: davesweb Date: Wed, 25 Aug 2021 04:39:07 +0200 Subject: [PATCH 11/12] Rename namespace for parameter objects --- src/{Enums => ParameterObjects}/CouponStatus.php | 2 +- src/{Enums => ParameterObjects}/Direction.php | 2 +- src/{Enums => ParameterObjects}/GuideType.php | 2 +- src/{Enums => ParameterObjects}/Id.php | 2 +- src/{Enums => ParameterObjects}/InventoryStatus.php | 2 +- src/{Enums => ParameterObjects}/ItemType.php | 2 +- src/{Enums => ParameterObjects}/NewOrUsed.php | 2 +- src/{Enums => ParameterObjects}/OrderPaymentStatus.php | 2 +- src/{Enums => ParameterObjects}/OrderStatus.php | 2 +- src/Repositories/CouponRepository.php | 4 ++-- src/Repositories/FeedbackRepository.php | 2 +- src/Repositories/InventoryRepository.php | 6 +++--- src/Repositories/ItemRepository.php | 2 +- src/Repositories/MappingRepository.php | 2 +- src/Repositories/OrderRepository.php | 6 +++--- src/Repositories/PriceGuideRepository.php | 6 +++--- src/Repositories/SubsetRepository.php | 2 +- src/Repositories/SupersetRepository.php | 2 +- tests/Feature/OrderTest.php | 4 ++-- tests/Unit/Enums/CouponStatusTest.php | 2 +- tests/Unit/Enums/DirectionTest.php | 2 +- tests/Unit/Enums/GuideTypeTest.php | 2 +- tests/Unit/Enums/IdTest.php | 2 +- tests/Unit/Enums/InventoryStatusTest.php | 2 +- tests/Unit/Enums/ItemTypeTest.php | 2 +- tests/Unit/Enums/NewOrUsedTest.php | 2 +- tests/Unit/Enums/OrderPaymentStatusTest.php | 2 +- tests/Unit/Enums/OrderStatusTest.php | 2 +- 28 files changed, 36 insertions(+), 36 deletions(-) rename src/{Enums => ParameterObjects}/CouponStatus.php (96%) rename src/{Enums => ParameterObjects}/Direction.php (95%) rename src/{Enums => ParameterObjects}/GuideType.php (95%) rename src/{Enums => ParameterObjects}/Id.php (94%) rename src/{Enums => ParameterObjects}/InventoryStatus.php (97%) rename src/{Enums => ParameterObjects}/ItemType.php (98%) rename src/{Enums => ParameterObjects}/NewOrUsed.php (94%) rename src/{Enums => ParameterObjects}/OrderPaymentStatus.php (97%) rename src/{Enums => ParameterObjects}/OrderStatus.php (98%) diff --git a/src/Enums/CouponStatus.php b/src/ParameterObjects/CouponStatus.php similarity index 96% rename from src/Enums/CouponStatus.php rename to src/ParameterObjects/CouponStatus.php index f6aec42..c246bf0 100644 --- a/src/Enums/CouponStatus.php +++ b/src/ParameterObjects/CouponStatus.php @@ -1,6 +1,6 @@ Date: Wed, 25 Aug 2021 04:42:39 +0200 Subject: [PATCH 12/12] Update roadmap in readme --- readme.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index bb170c3..2bdde40 100644 --- a/readme.md +++ b/readme.md @@ -106,13 +106,10 @@ To run CS fixer on the entire project, run `composer cs-fixer`. These features/enhancements will be added in future releases: -- Support for PHP 8.1 -- Add constants for the parameters that have a defined set of possible values, like the direction parameter on orders - for the PHP 8.0 version. -- Add Enums for the parameters that have a defined set of possible values, like the direction parameter on orders for - the PHP 8.1 version. -- Validate the values on parameters. +- Support for PHP 8.1. +- ~~Validate the values on parameters.~~ - Finish documentation about repositories. +- Add docker setup for local development. ## License