From 888d70f20c93278ea525c448d88a9f114b5649ae Mon Sep 17 00:00:00 2001 From: Oleksandr Mykhailenko Date: Mon, 27 Nov 2023 12:37:06 +0200 Subject: [PATCH] Bugxfixes and changes (#881) * Bugxfixes and changes * php cs fixes --- CHANGELOG.md | 8 +++++++ README.md | 2 +- src/Hydrator/ArrayHydrator.php | 6 +++--- src/Hydrator/ModelHydrator.php | 6 +++--- src/Model/Suppression/BaseResponse.php | 4 ++++ src/Model/Suppression/Bounce/Bounce.php | 21 +++++++++++++++++-- .../Suppression/Bounce/IndexResponse.php | 3 ++- src/Model/Suppression/Complaint/Complaint.php | 15 +++++++++++-- .../Suppression/Complaint/IndexResponse.php | 5 +++++ .../Suppression/Unsubscribe/IndexResponse.php | 8 +++++++ .../Suppression/Unsubscribe/Unsubscribe.php | 18 ++++++++++++++-- .../Suppression/Whitelist/IndexResponse.php | 8 +++++++ src/Model/Suppression/Whitelist/Whitelist.php | 15 +++++++++++++ 13 files changed, 105 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a836dec..9e55ee3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Change Log The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 3.6.2 + - Bugfix: TypeError caused by improper use of new self() instead of new static() in base class method + +## 3.6.1 + - update library + - Improvement: SDK version headers v2 vs v3 + - Update packages by @oleksandr-mykhailenko + ## 3.5.9 - Fixed: bug when params `to` and `reply-to` have the same address diff --git a/README.md b/README.md index afc211e3..e206a689 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ curl -sS https://getcomposer.org/installer | php ``` ## Required minimum php version - - minimum php version 8.1 + - minimum php version 7.3 The Mailgun API Client is not hard coupled to Guzzle, Buzz or any other library that sends HTTP messages. Instead, it uses the [PSR-18](https://www.php-fig.org/psr/psr-18/) client abstraction. diff --git a/src/Hydrator/ArrayHydrator.php b/src/Hydrator/ArrayHydrator.php index 806b7d9c..dd069bfb 100644 --- a/src/Hydrator/ArrayHydrator.php +++ b/src/Hydrator/ArrayHydrator.php @@ -22,9 +22,9 @@ final class ArrayHydrator implements Hydrator { /** - * @param class-string $class - * + * @param class-string $class * @return array + * @throws \JsonException */ public function hydrate(ResponseInterface $response, string $class) { @@ -33,7 +33,7 @@ public function hydrate(ResponseInterface $response, string $class) throw new HydrationException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type')); } - $content = json_decode($body, true); + $content = json_decode($body, true, 512, JSON_THROW_ON_ERROR); if (JSON_ERROR_NONE !== json_last_error()) { throw new HydrationException(sprintf('Error (%d) when trying to json_decode response', json_last_error())); } diff --git a/src/Hydrator/ModelHydrator.php b/src/Hydrator/ModelHydrator.php index cb4421bd..98666b98 100644 --- a/src/Hydrator/ModelHydrator.php +++ b/src/Hydrator/ModelHydrator.php @@ -23,9 +23,9 @@ final class ModelHydrator implements Hydrator { /** - * @param class-string $class - * + * @param class-string $class * @return ResponseInterface + * @throws \JsonException */ public function hydrate(ResponseInterface $response, string $class) { @@ -36,7 +36,7 @@ public function hydrate(ResponseInterface $response, string $class) throw new HydrationException('The ModelHydrator cannot hydrate response with Content-Type: '.$contentType); } - $data = json_decode($body, true); + $data = json_decode($body, true, 512, JSON_THROW_ON_ERROR); if (JSON_ERROR_NONE !== json_last_error()) { throw new HydrationException(sprintf('Error (%d) when trying to json_decode response', json_last_error())); diff --git a/src/Model/Suppression/BaseResponse.php b/src/Model/Suppression/BaseResponse.php index 93064377..731cf2fa 100644 --- a/src/Model/Suppression/BaseResponse.php +++ b/src/Model/Suppression/BaseResponse.php @@ -27,6 +27,10 @@ final private function __construct() { } + /** + * @param array $data + * @return static + */ public static function create(array $data): self { $model = new static(); diff --git a/src/Model/Suppression/Bounce/Bounce.php b/src/Model/Suppression/Bounce/Bounce.php index a8719d74..b2438ffe 100644 --- a/src/Model/Suppression/Bounce/Bounce.php +++ b/src/Model/Suppression/Bounce/Bounce.php @@ -11,6 +11,8 @@ namespace Mailgun\Model\Suppression\Bounce; +use DateTimeImmutable; + /** * @author Sean Johnson */ @@ -25,33 +27,48 @@ final private function __construct() { } + /** + * @throws \Exception + */ public static function create(array $data): self { $model = new static(); $model->address = $data['address'] ?? null; $model->code = $data['code'] ?? null; $model->error = $data['error'] ?? null; - $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; + $model->createdAt = isset($data['created_at']) ? new DateTimeImmutable($data['created_at']) : null; return $model; } + /** + * @return string|null + */ public function getAddress(): ?string { return $this->address; } + /** + * @return string|null + */ public function getCode(): ?string { return $this->code; } + /** + * @return string|null + */ public function getError(): ?string { return $this->error; } - public function getCreatedAt(): ?\DateTimeImmutable + /** + * @return DateTimeImmutable|null + */ + public function getCreatedAt(): ?DateTimeImmutable { return $this->createdAt; } diff --git a/src/Model/Suppression/Bounce/IndexResponse.php b/src/Model/Suppression/Bounce/IndexResponse.php index 16d683c0..bf09ce8e 100644 --- a/src/Model/Suppression/Bounce/IndexResponse.php +++ b/src/Model/Suppression/Bounce/IndexResponse.php @@ -29,8 +29,9 @@ private function __construct() } /** - * @param array $data + * @param array $data * @return static + * @throws \Exception */ public static function create(array $data): self { diff --git a/src/Model/Suppression/Complaint/Complaint.php b/src/Model/Suppression/Complaint/Complaint.php index 43346b2e..6ce2ad2e 100644 --- a/src/Model/Suppression/Complaint/Complaint.php +++ b/src/Model/Suppression/Complaint/Complaint.php @@ -11,6 +11,8 @@ namespace Mailgun\Model\Suppression\Complaint; +use DateTimeImmutable; + /** * @author Sean Johnson */ @@ -23,21 +25,30 @@ final private function __construct() { } + /** + * @throws \Exception + */ public static function create(array $data): self { $model = new static(); $model->address = $data['address'] ?? null; - $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; + $model->createdAt = isset($data['created_at']) ? new DateTimeImmutable($data['created_at']) : null; return $model; } + /** + * @return string|null + */ public function getAddress(): ?string { return $this->address; } - public function getCreatedAt(): ?\DateTimeImmutable + /** + * @return DateTimeImmutable|null + */ + public function getCreatedAt(): ?DateTimeImmutable { return $this->createdAt; } diff --git a/src/Model/Suppression/Complaint/IndexResponse.php b/src/Model/Suppression/Complaint/IndexResponse.php index 268ff21c..16402240 100644 --- a/src/Model/Suppression/Complaint/IndexResponse.php +++ b/src/Model/Suppression/Complaint/IndexResponse.php @@ -28,6 +28,11 @@ private function __construct() { } + /** + * @param array $data + * @return static + * @throws \Exception + */ public static function create(array $data): self { $complaints = []; diff --git a/src/Model/Suppression/Unsubscribe/IndexResponse.php b/src/Model/Suppression/Unsubscribe/IndexResponse.php index 7c4403f8..40e07263 100644 --- a/src/Model/Suppression/Unsubscribe/IndexResponse.php +++ b/src/Model/Suppression/Unsubscribe/IndexResponse.php @@ -45,6 +45,11 @@ private function __construct() { } + /** + * @param array $data + * @return static + * @throws \Exception + */ public static function create(array $data): self { $unsubscribes = []; @@ -69,6 +74,9 @@ public function getItems(): array return $this->items; } + /** + * @return int + */ public function getTotalCount(): int { if (null === $this->totalCount) { diff --git a/src/Model/Suppression/Unsubscribe/Unsubscribe.php b/src/Model/Suppression/Unsubscribe/Unsubscribe.php index dbf82a93..290db6c8 100644 --- a/src/Model/Suppression/Unsubscribe/Unsubscribe.php +++ b/src/Model/Suppression/Unsubscribe/Unsubscribe.php @@ -11,6 +11,8 @@ namespace Mailgun\Model\Suppression\Unsubscribe; +use DateTimeImmutable; + /** * @author Sean Johnson */ @@ -24,26 +26,38 @@ final private function __construct() { } + /** + * @throws \Exception + */ public static function create(array $data): 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; + $model->createdAt = isset($data['created_at']) ? new DateTimeImmutable($data['created_at']) : null; return $model; } + /** + * @return string|null + */ public function getAddress(): ?string { return $this->address; } - public function getCreatedAt(): ?\DateTimeImmutable + /** + * @return DateTimeImmutable|null + */ + public function getCreatedAt(): ?DateTimeImmutable { return $this->createdAt; } + /** + * @return array + */ public function getTags(): array { return $this->tags; diff --git a/src/Model/Suppression/Whitelist/IndexResponse.php b/src/Model/Suppression/Whitelist/IndexResponse.php index 613ec80a..06f0cf8e 100644 --- a/src/Model/Suppression/Whitelist/IndexResponse.php +++ b/src/Model/Suppression/Whitelist/IndexResponse.php @@ -41,6 +41,11 @@ private function __construct() { } + /** + * @param array $data + * @return static + * @throws \Exception + */ public static function create(array $data): self { $whitelists = []; @@ -66,6 +71,9 @@ public function getItems(): array return $this->items; } + /** + * @return int + */ public function getTotalCount(): int { if (null === $this->totalCount) { diff --git a/src/Model/Suppression/Whitelist/Whitelist.php b/src/Model/Suppression/Whitelist/Whitelist.php index 30a6cba4..144798a0 100644 --- a/src/Model/Suppression/Whitelist/Whitelist.php +++ b/src/Model/Suppression/Whitelist/Whitelist.php @@ -27,6 +27,9 @@ final private function __construct() { } + /** + * @throws \Exception + */ public static function create(array $data): self { $model = new static(); @@ -38,21 +41,33 @@ public static function create(array $data): self return $model; } + /** + * @return string|null + */ public function getValue(): ?string { return $this->value; } + /** + * @return string|null + */ public function getReason(): ?string { return $this->reason; } + /** + * @return string|null + */ public function getType(): ?string { return $this->type; } + /** + * @return DateTimeImmutable|null + */ public function getCreatedAt(): ?DateTimeImmutable { return $this->createdAt;