Skip to content

Commit

Permalink
Bugfix: TypeError caused by improper use of new self() instead of `…
Browse files Browse the repository at this point in the history
…new static()` in base class method (#878) (#879)

Co-authored-by: Kai Hu <kai.hu@rightcapital.com>
  • Loading branch information
Quarkay and Kai Hu authored Nov 27, 2023
1 parent c5162d1 commit 57d5531
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Model/Suppression/Bounce/Bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class Bounce
private $error;
private $createdAt;

private function __construct()
final private function __construct()
{
}

public static function create(array $data): self
{
$model = new self();
$model = new static();
$model->address = $data['address'] ?? null;
$model->code = $data['code'] ?? null;
$model->error = $data['error'] ?? null;
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Suppression/Complaint/Complaint.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class Complaint
private $address;
private $createdAt;

private function __construct()
final private function __construct()
{
}

public static function create(array $data): self
{
$model = new self();
$model = new static();
$model->address = $data['address'] ?? null;
$model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Suppression/Unsubscribe/Unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class Unsubscribe
private $createdAt;
private $tags = [];

private function __construct()
final private function __construct()
{
}

public static function create(array $data): self
{
$model = new self();
$model = new static();
$model->tags = $data['tags'] ?? [];
$model->address = $data['address'] ?? null;
$model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Suppression/Whitelist/DeleteResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final private function __construct()

public static function create(array $data): self
{
$model = new static();
$model = new self();
$model->value = $data['value'] ?? '';
$model->message = $data['message'] ?? '';

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Suppression/Whitelist/Whitelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class Whitelist
private $type;
private $createdAt;

private function __construct()
final private function __construct()
{
}

public static function create(array $data): self
{
$model = new self();
$model = new static();
$model->value = $data['value'] ?? null;
$model->reason = $data['reason'] ?? null;
$model->type = $data['type'] ?? null;
Expand Down
1 change: 1 addition & 0 deletions tests/Model/Suppression/Whitelists/ShowResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public function testCreate()
$this->assertEquals('why the record was created', $model->getReason());
$this->assertEquals('address', $model->getType());
$this->assertEquals('2011-10-21 11:02:55', $model->getCreatedAt()->format('Y-m-d H:i:s'));
$this->assertInstanceOf(ShowResponse::class, $model);
}
}

0 comments on commit 57d5531

Please sign in to comment.