Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HP-1928: array => string type #64

Merged
merged 11 commits into from
Jun 5, 2024
4 changes: 2 additions & 2 deletions src/sale/Sale.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ public function setId($id)
$this->id = $id;
}

public function getData()
public function getData(): ?array
{
return $this->data;
return !empty($this->data) ? $this->data : null;
Comment on lines +132 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update getData method to handle JSON strings.

The getData method should return an array decoded from the JSON string stored in $data, as per the PR's objective and the AI-generated summary. Currently, it still treats $data as an array.

- return !empty($this->data) ? $this->data : null;
+ return !empty($this->data) ? json_decode($this->data, true) : null;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public function getData(): ?array
{
return $this->data;
return !empty($this->data) ? $this->data : null;
public function getData(): ?array
{
return !empty($this->data) ? json_decode($this->data, true) : null;

}

public function jsonSerialize(): array
Expand Down
2 changes: 2 additions & 0 deletions src/sale/SaleCreationDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ class SaleCreationDto
public $closeTime;

public $data;

public $reason;
}
2 changes: 1 addition & 1 deletion src/sale/SaleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SaleFactory implements SaleFactoryInterface
*/
public function create(SaleCreationDto $dto)
{
$sale = new Sale($dto->id, $dto->target, $dto->customer, $dto->plan, $dto->time);
$sale = new Sale($dto->id, $dto->target, $dto->customer, $dto->plan, $dto->time, $dto->data);

if ($dto->closeTime !== null) {
$sale->close($dto->closeTime);
Expand Down
4 changes: 2 additions & 2 deletions src/sale/SaleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function getTime();
public function getCloseTime(): ?DateTimeImmutable;

/**
* @return string|array|null
* @return array|null
*/
public function getData();
public function getData(): ?array;

/**
* @param DateTimeImmutable $time
Expand Down
Loading