Skip to content

Commit

Permalink
Bugxfixes and changes (#881)
Browse files Browse the repository at this point in the history
* Bugxfixes and changes

* php cs fixes
  • Loading branch information
oleksandr-mykhailenko committed Nov 27, 2023
1 parent 57d5531 commit 888d70f
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/Hydrator/ArrayHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);

This comment has been minimized.

Copy link
@cswiers

cswiers Nov 29, 2023

This change brakes the execution in of $mg->domains()->index() when a account has a relatively large list of domains (61)

If I look closely it looks like the request contains a trailing space at the end triggering a JSON syntax error. This can either be fixed in the request, or by adding a trim to this line.

if (JSON_ERROR_NONE !== json_last_error()) {
throw new HydrationException(sprintf('Error (%d) when trying to json_decode response', json_last_error()));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Hydrator/ModelHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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()));
Expand Down
4 changes: 4 additions & 0 deletions src/Model/Suppression/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ final private function __construct()
{
}

/**
* @param array $data
* @return static
*/
public static function create(array $data): self
{
$model = new static();
Expand Down
21 changes: 19 additions & 2 deletions src/Model/Suppression/Bounce/Bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Mailgun\Model\Suppression\Bounce;

use DateTimeImmutable;

/**
* @author Sean Johnson <[email protected]>
*/
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Suppression/Bounce/IndexResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ private function __construct()
}

/**
* @param array $data
* @param array $data
* @return static
* @throws \Exception
*/
public static function create(array $data): self
{
Expand Down
15 changes: 13 additions & 2 deletions src/Model/Suppression/Complaint/Complaint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Mailgun\Model\Suppression\Complaint;

use DateTimeImmutable;

/**
* @author Sean Johnson <[email protected]>
*/
Expand All @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Model/Suppression/Complaint/IndexResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ private function __construct()
{
}

/**
* @param array $data
* @return static
* @throws \Exception
*/
public static function create(array $data): self
{
$complaints = [];
Expand Down
8 changes: 8 additions & 0 deletions src/Model/Suppression/Unsubscribe/IndexResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ private function __construct()
{
}

/**
* @param array $data
* @return static
* @throws \Exception
*/
public static function create(array $data): self
{
$unsubscribes = [];
Expand All @@ -69,6 +74,9 @@ public function getItems(): array
return $this->items;
}

/**
* @return int
*/
public function getTotalCount(): int
{
if (null === $this->totalCount) {
Expand Down
18 changes: 16 additions & 2 deletions src/Model/Suppression/Unsubscribe/Unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Mailgun\Model\Suppression\Unsubscribe;

use DateTimeImmutable;

/**
* @author Sean Johnson <[email protected]>
*/
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/Model/Suppression/Whitelist/IndexResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ private function __construct()
{
}

/**
* @param array $data
* @return static
* @throws \Exception
*/
public static function create(array $data): self
{
$whitelists = [];
Expand All @@ -66,6 +71,9 @@ public function getItems(): array
return $this->items;
}

/**
* @return int
*/
public function getTotalCount(): int
{
if (null === $this->totalCount) {
Expand Down
15 changes: 15 additions & 0 deletions src/Model/Suppression/Whitelist/Whitelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ final private function __construct()
{
}

/**
* @throws \Exception
*/
public static function create(array $data): self
{
$model = new static();
Expand All @@ -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;
Expand Down

0 comments on commit 888d70f

Please sign in to comment.