mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Updating Stats models to PHP7 code
This commit is contained in:
parent
a7f8c14fe8
commit
61ae9bc945
@ -18,30 +18,14 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
final class AllResponse implements ApiResponse
|
final class AllResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $totalCount;
|
private $totalCount;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var AllResponseItem[]
|
|
||||||
*/
|
|
||||||
private $items;
|
private $items;
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param int $totalCount
|
|
||||||
* @param AllResponseItem[] $items
|
|
||||||
*/
|
|
||||||
private function __construct($totalCount, array $items)
|
|
||||||
{
|
{
|
||||||
$this->totalCount = $totalCount;
|
|
||||||
$this->items = $items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
$items = [];
|
$items = [];
|
||||||
if (isset($data['items'])) {
|
if (isset($data['items'])) {
|
||||||
@ -50,19 +34,14 @@ final class AllResponse implements ApiResponse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['total_count'])) {
|
$model = new self();
|
||||||
$count = $data['total_count'];
|
$model->totalCount = (int) ($data['total_count'] ?? count($items));
|
||||||
} else {
|
$model->items = $items;
|
||||||
$count = count($items);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new self($count, $items);
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getTotalCount(): int
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getTotalCount()
|
|
||||||
{
|
{
|
||||||
return $this->totalCount;
|
return $this->totalCount;
|
||||||
}
|
}
|
||||||
@ -70,7 +49,7 @@ final class AllResponse implements ApiResponse
|
|||||||
/**
|
/**
|
||||||
* @return AllResponseItem[]
|
* @return AllResponseItem[]
|
||||||
*/
|
*/
|
||||||
public function getItems()
|
public function getItems(): array
|
||||||
{
|
{
|
||||||
return $this->items;
|
return $this->items;
|
||||||
}
|
}
|
||||||
|
@ -16,80 +16,39 @@ namespace Mailgun\Model\Stats;
|
|||||||
*/
|
*/
|
||||||
final class AllResponseItem
|
final class AllResponseItem
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $event;
|
private $event;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $totalCount;
|
private $totalCount;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private $tags;
|
private $tags;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \DateTime
|
|
||||||
*/
|
|
||||||
private $createdAt;
|
private $createdAt;
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
return new self(
|
$model = new self();
|
||||||
isset($data['id']) ? $data['id'] : null,
|
$model->id = $data['id'] ?? null;
|
||||||
isset($data['event']) ? $data['event'] : null,
|
$model->event = $data['event'] ?? null;
|
||||||
isset($data['total_count']) ? $data['total_count'] : null,
|
$model->totalCount = (int) ($data['total_count'] ?? 0);
|
||||||
isset($data['tags']) ? $data['tags'] : null,
|
$model->tags = $data['tags'] ?? [];
|
||||||
isset($data['created_at']) ? new \DateTime($data['created_at']) : null
|
$model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
|
||||||
);
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param string $id
|
|
||||||
* @param string $event
|
|
||||||
* @param string $totalCount
|
|
||||||
* @param string[] $tags
|
|
||||||
*/
|
|
||||||
private function __construct($id, $event, $totalCount, array $tags, \DateTime $createdAt)
|
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
|
||||||
$this->event = $event;
|
|
||||||
$this->totalCount = $totalCount;
|
|
||||||
$this->tags = $tags;
|
|
||||||
$this->createdAt = $createdAt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getId(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getEvent(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getEvent()
|
|
||||||
{
|
{
|
||||||
return $this->event;
|
return $this->event;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getTotalCount(): int
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getTotalCount()
|
|
||||||
{
|
{
|
||||||
return $this->totalCount;
|
return $this->totalCount;
|
||||||
}
|
}
|
||||||
@ -97,15 +56,12 @@ final class AllResponseItem
|
|||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function getTags()
|
public function getTags(): array
|
||||||
{
|
{
|
||||||
return $this->tags;
|
return $this->tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getCreatedAt(): ?\DateTimeImmutable
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public function getCreatedAt()
|
|
||||||
{
|
{
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
@ -18,42 +18,16 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
final class TotalResponse implements ApiResponse
|
final class TotalResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \DateTime
|
|
||||||
*/
|
|
||||||
private $start;
|
private $start;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \DateTime
|
|
||||||
*/
|
|
||||||
private $end;
|
private $end;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $resolution;
|
private $resolution;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var TotalResponseItem[]
|
|
||||||
*/
|
|
||||||
private $stats;
|
private $stats;
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param string $resolution
|
|
||||||
* @param TotalResponseItem[] $stats
|
|
||||||
*/
|
|
||||||
private function __construct(\DateTime $start, \DateTime $end, $resolution, array $stats)
|
|
||||||
{
|
{
|
||||||
$this->start = $start;
|
|
||||||
$this->end = $end;
|
|
||||||
$this->resolution = $resolution;
|
|
||||||
$this->stats = $stats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
$stats = [];
|
$stats = [];
|
||||||
if (isset($data['stats'])) {
|
if (isset($data['stats'])) {
|
||||||
@ -62,33 +36,26 @@ final class TotalResponse implements ApiResponse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$start = isset($data['start']) ? new \DateTime($data['start']) : null;
|
$model = new self();
|
||||||
$end = isset($data['end']) ? new \DateTime($data['end']) : null;
|
$model->start = isset($data['start']) ? new \DateTimeImmutable($data['start']) : null;
|
||||||
$resolution = isset($data['resolution']) ? $data['resolution'] : null;
|
$model->end = isset($data['end']) ? new \DateTimeImmutable($data['end']) : null;
|
||||||
|
$model->resolution = $data['resolution'] ?? null;
|
||||||
|
$model->stats = $stats;
|
||||||
|
|
||||||
return new self($start, $end, $resolution, $stats);
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getStart(): ?\DateTimeImmutable
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public function getStart()
|
|
||||||
{
|
{
|
||||||
return $this->start;
|
return $this->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getEnd(): ?\DateTimeImmutable
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public function getEnd()
|
|
||||||
{
|
{
|
||||||
return $this->end;
|
return $this->end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getResolution(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getResolution()
|
|
||||||
{
|
{
|
||||||
return $this->resolution;
|
return $this->resolution;
|
||||||
}
|
}
|
||||||
@ -96,7 +63,7 @@ final class TotalResponse implements ApiResponse
|
|||||||
/**
|
/**
|
||||||
* @return TotalResponseItem[]
|
* @return TotalResponseItem[]
|
||||||
*/
|
*/
|
||||||
public function getStats()
|
public function getStats(): array
|
||||||
{
|
{
|
||||||
return $this->stats;
|
return $this->stats;
|
||||||
}
|
}
|
||||||
|
@ -16,90 +16,49 @@ namespace Mailgun\Model\Stats;
|
|||||||
*/
|
*/
|
||||||
final class TotalResponseItem
|
final class TotalResponseItem
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \DateTime
|
|
||||||
*/
|
|
||||||
private $time;
|
private $time;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $accepted;
|
private $accepted;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $delivered;
|
private $delivered;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $failed;
|
private $failed;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $complained;
|
private $complained;
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
return new self(
|
$model = new self();
|
||||||
isset($data['time']) ? new \DateTime($data['time']) : null,
|
$model->time = isset($data['time']) ? new \DateTimeImmutable($data['time']) : null;
|
||||||
isset($data['accepted']) ? $data['accepted'] : [],
|
$model->accepted = $data['accepted'] ?? [];
|
||||||
isset($data['delivered']) ? $data['delivered'] : [],
|
$model->delivered = $data['delivered'] ?? [];
|
||||||
isset($data['failed']) ? $data['failed'] : [],
|
$model->failed = $data['failed'] ?? [];
|
||||||
isset($data['complained']) ? $data['complained'] : []
|
$model->complained = $data['complained'] ?? [];
|
||||||
);
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function __construct(\DateTime $time, array $accepted, array $delivered, array $failed, array $complained)
|
private function __construct()
|
||||||
{
|
{
|
||||||
$this->time = $time;
|
|
||||||
$this->accepted = $accepted;
|
|
||||||
$this->delivered = $delivered;
|
|
||||||
$this->failed = $failed;
|
|
||||||
$this->complained = $complained;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getTime(): ?\DateTimeImmutable
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public function getTime()
|
|
||||||
{
|
{
|
||||||
return $this->time;
|
return $this->time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getAccepted(): array
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getAccepted()
|
|
||||||
{
|
{
|
||||||
return $this->accepted;
|
return $this->accepted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getDelivered(): array
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getDelivered()
|
|
||||||
{
|
{
|
||||||
return $this->delivered;
|
return $this->delivered;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getFailed(): array
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFailed()
|
|
||||||
{
|
{
|
||||||
return $this->failed;
|
return $this->failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getComplained(): array
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getComplained()
|
|
||||||
{
|
{
|
||||||
return $this->complained;
|
return $this->complained;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user