Skip to content

Commit

Permalink
Refactor ApiProblem and Response classes
Browse files Browse the repository at this point in the history
Removed 'readonly' attribute from properties in ApiProblem and Response classes and introduced classic setters in constructor. This is a part of an ongoing initiative to refactor our codebase for better readability and maintainability. This change also improves compatibility with various PHP versions.

Signed-off-by: B24io <app@b24.io>
  • Loading branch information
b24io-sdk committed May 22, 2024
1 parent 2bb553c commit 461ef32
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
39 changes: 32 additions & 7 deletions src/Core/Response/ApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,41 @@

namespace B24io\Loyalty\SDK\Core\Response;

readonly class ApiProblem
class ApiProblem
{
/**
* @readonly
*/
public string $title;
/**
* @readonly
*/
public string $type;
/**
* @readonly
*/
public int $status;
/**
* @readonly
*/
public string $detail;
/**
* @readonly
*/
public string $instance;

public function __construct(
public string $title,
public string $type,
public int $status,
public string $detail,
public string $instance,
)
string $title,
string $type,
int $status,
string $detail,
string $instance)
{
$this->title = $title;
$this->type = $type;
$this->status = $status;
$this->detail = $detail;
$this->instance = $instance;
}

/**
Expand Down
28 changes: 22 additions & 6 deletions src/Core/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use B24io\Loyalty\SDK\Core\Command;
use B24io\Loyalty\SDK\Core\Exceptions\BaseException;
use B24io\Loyalty\SDK\Core\Exceptions\TransportException;
use B24io\Loyalty\SDK\Core\Response\DTO\Metadata;
use B24io\Loyalty\SDK\Core\Response\DTO\Pagination;
use Psr\Log\LoggerInterface;
Expand All @@ -15,13 +14,30 @@

class Response
{
/**
* @readonly
*/
public ResponseInterface $httpResponse;
/**
* @readonly
*/
public Command $apiCommand;
/**
* @readonly
*/
private LoggerInterface $logger;
private ?DTO\ResponseData $responseData = null;

public function __construct(
public readonly ResponseInterface $httpResponse,
public readonly Command $apiCommand,
private readonly LoggerInterface $logger,
private ?DTO\ResponseData $responseData = null,
)
ResponseInterface $httpResponse,
Command $apiCommand,
LoggerInterface $logger,
?DTO\ResponseData $responseData = null)
{
$this->httpResponse = $httpResponse;
$this->apiCommand = $apiCommand;
$this->logger = $logger;
$this->responseData = $responseData;
}

/**
Expand Down

0 comments on commit 461ef32

Please sign in to comment.