Skip to content

Change type data from array to mixed #63

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/sale/Sale.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ class Sale implements SaleInterface

protected ?DateTimeImmutable $closeTime = null;

protected ?array $data = null;
protected mixed $data = null;

public function __construct(
$id,
TargetInterface $target,
CustomerInterface $customer,
?PlanInterface $plan = null,
?DateTimeImmutable $time = null,
?array $data = null,
mixed $data = null,
) {
$this->id = $id;
$this->target = $target;
$this->customer = $customer;
$this->plan = $plan;
$this->time = $time ?? new DateTimeImmutable();
$this->data = $data;
$this->data = $this->setData($data);
}

public function getId()
Expand Down Expand Up @@ -129,6 +129,23 @@ public function setId($id)
$this->id = $id;
}

public function setData(mixed $data = null)
{
if (is_null($data) || empty($data)) {
return ;
}
if ($is_string($data)) {
$this->data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
return ;
}

if (is_object($data)) {
$this->data = json_decode(json_encode($data), true, 512, JSON_THROW_ON_ERROR);
}

$this->data = $data;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Correct the typo in the function call ($is_string should be is_string).
  2. Consider adding a return type of void to the setData method to clarify that it does not return any value.
- if ($is_string($data)) {
+ if (is_string($data)) {
  $this->data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
  return ;
}
- public function setData(mixed $data = null)
+ public function setData(mixed $data = null): void

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 setData(mixed $data = null)
{
if (is_null($data) || empty($data)) {
return ;
}
if ($is_string($data)) {
$this->data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
return ;
}
if (is_object($data)) {
$this->data = json_decode(json_encode($data), true, 512, JSON_THROW_ON_ERROR);
}
$this->data = $data;
}
public function setData(mixed $data = null): void
{
if (is_null($data) || empty($data)) {
return ;
}
if (is_string($data)) {
$this->data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
return ;
}
if (is_object($data)) {
$this->data = json_decode(json_encode($data), true, 512, JSON_THROW_ON_ERROR);
}
$this->data = $data;
}


public function getData()
{
return $this->data;
Expand Down