Skip to content

Commit

Permalink
Add update method to products and change the update methods signature
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 29, 2024
1 parent 89918ea commit e6361a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Client/Endpoint/ProductEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ final class ProductEndpoint extends Endpoint implements ProductEndpointInterface

use DeletableEndpointTrait;

/**
* @use UpdatableEndpointTrait<Product>
*/
use UpdatableEndpointTrait;

/**
* @return PaginatedCollection<Product>
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Endpoint/UpdatableEndpointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface UpdatableEndpointInterface
{
/**
* @param mixed $id This is (most likely) the host id
* @param mixed|null $id This is (most likely) the host id. Some endpoints require this to be set
*/
public function update(mixed $id, AbstractDataTransferObject $data): void;
public function update(AbstractDataTransferObject $data, mixed $id = null): void;
}
5 changes: 3 additions & 2 deletions src/Client/Endpoint/UpdatableEndpointTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ trait UpdatableEndpointTrait
/**
* @param T|AbstractDataTransferObject $data
*/
public function update(mixed $id, AbstractDataTransferObject $data): void
public function update(AbstractDataTransferObject $data, mixed $id = null): void
{
$this->client->put(sprintf('%s/%s', $this->endpoint, (string) $id), $data);
$endpoint = null === $id ? $this->endpoint : sprintf('%s/%s', $this->endpoint, (string) $id);
$this->client->put($endpoint, $data);
}
}

0 comments on commit e6361a5

Please sign in to comment.