Skip to content

Commit

Permalink
add generic types for dto and dtoOrFail
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldyrynda committed Apr 13, 2024
1 parent 25cecb8 commit 9329464
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ public function collect(string|int|null $key = null): Collection

/**
* Cast the response to a DTO.
*
* @template T of object
* @return ($dto is class-string<T> ? T : object)
*/
public function dto(): mixed
public function dto(?string $dto = null): mixed
{
$request = $this->pendingRequest->getRequest();
$connector = $this->pendingRequest->getConnector();
Expand All @@ -304,8 +307,11 @@ public function dto(): mixed

/**
* Convert the response into a DTO or throw a LogicException if the response failed
*
* @template T of object
* @return ($dto is class-string<T> ? T : object)
*/
public function dtoOrFail(): mixed
public function dtoOrFail(?string $dto = null): mixed
{
if ($this->failed()) {
throw new LogicException('Unable to create data transfer object as the response has failed.', 0, $this->toException());
Expand Down

0 comments on commit 9329464

Please sign in to comment.