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
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $totalCount;
|
||||
|
||||
/**
|
||||
* @var AllResponseItem[]
|
||||
*/
|
||||
private $items;
|
||||
|
||||
/**
|
||||
* @param int $totalCount
|
||||
* @param AllResponseItem[] $items
|
||||
*/
|
||||
private function __construct($totalCount, array $items)
|
||||
private function __construct()
|
||||
{
|
||||
$this->totalCount = $totalCount;
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public static function create(array $data)
|
||||
public static function create(array $data): self
|
||||
{
|
||||
$items = [];
|
||||
if (isset($data['items'])) {
|
||||
@ -50,19 +34,14 @@ final class AllResponse implements ApiResponse
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['total_count'])) {
|
||||
$count = $data['total_count'];
|
||||
} else {
|
||||
$count = count($items);
|
||||
$model = new self();
|
||||
$model->totalCount = (int) ($data['total_count'] ?? count($items));
|
||||
$model->items = $items;
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
return new self($count, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCount()
|
||||
public function getTotalCount(): int
|
||||
{
|
||||
return $this->totalCount;
|
||||
}
|
||||
@ -70,7 +49,7 @@ final class AllResponse implements ApiResponse
|
||||
/**
|
||||
* @return AllResponseItem[]
|
||||
*/
|
||||
public function getItems()
|
||||
public function getItems(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
@ -16,80 +16,39 @@ namespace Mailgun\Model\Stats;
|
||||
*/
|
||||
final class AllResponseItem
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $event;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $totalCount;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $tags;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public static function create(array $data)
|
||||
public static function create(array $data): self
|
||||
{
|
||||
return new self(
|
||||
isset($data['id']) ? $data['id'] : null,
|
||||
isset($data['event']) ? $data['event'] : null,
|
||||
isset($data['total_count']) ? $data['total_count'] : null,
|
||||
isset($data['tags']) ? $data['tags'] : null,
|
||||
isset($data['created_at']) ? new \DateTime($data['created_at']) : null
|
||||
);
|
||||
$model = new self();
|
||||
$model->id = $data['id'] ?? null;
|
||||
$model->event = $data['event'] ?? null;
|
||||
$model->totalCount = (int) ($data['total_count'] ?? 0);
|
||||
$model->tags = $data['tags'] ?? [];
|
||||
$model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $event
|
||||
* @param string $totalCount
|
||||
* @param string[] $tags
|
||||
*/
|
||||
private function __construct($id, $event, $totalCount, array $tags, \DateTime $createdAt)
|
||||
private function __construct()
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->event = $event;
|
||||
$this->totalCount = $totalCount;
|
||||
$this->tags = $tags;
|
||||
$this->createdAt = $createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEvent()
|
||||
public function getEvent(): ?string
|
||||
{
|
||||
return $this->event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTotalCount()
|
||||
public function getTotalCount(): int
|
||||
{
|
||||
return $this->totalCount;
|
||||
}
|
||||
@ -97,15 +56,12 @@ final class AllResponseItem
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTags()
|
||||
public function getTags(): array
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
public function getCreatedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
@ -18,42 +18,16 @@ use Mailgun\Model\ApiResponse;
|
||||
*/
|
||||
final class TotalResponse implements ApiResponse
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $start;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $end;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $resolution;
|
||||
|
||||
/**
|
||||
* @var TotalResponseItem[]
|
||||
*/
|
||||
private $stats;
|
||||
|
||||
/**
|
||||
* @param string $resolution
|
||||
* @param TotalResponseItem[] $stats
|
||||
*/
|
||||
private function __construct(\DateTime $start, \DateTime $end, $resolution, array $stats)
|
||||
private function __construct()
|
||||
{
|
||||
$this->start = $start;
|
||||
$this->end = $end;
|
||||
$this->resolution = $resolution;
|
||||
$this->stats = $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public static function create(array $data)
|
||||
public static function create(array $data): self
|
||||
{
|
||||
$stats = [];
|
||||
if (isset($data['stats'])) {
|
||||
@ -62,33 +36,26 @@ final class TotalResponse implements ApiResponse
|
||||
}
|
||||
}
|
||||
|
||||
$start = isset($data['start']) ? new \DateTime($data['start']) : null;
|
||||
$end = isset($data['end']) ? new \DateTime($data['end']) : null;
|
||||
$resolution = isset($data['resolution']) ? $data['resolution'] : null;
|
||||
$model = new self();
|
||||
$model->start = isset($data['start']) ? new \DateTimeImmutable($data['start']) : 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStart()
|
||||
public function getStart(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getEnd()
|
||||
public function getEnd(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResolution()
|
||||
public function getResolution(): ?string
|
||||
{
|
||||
return $this->resolution;
|
||||
}
|
||||
@ -96,7 +63,7 @@ final class TotalResponse implements ApiResponse
|
||||
/**
|
||||
* @return TotalResponseItem[]
|
||||
*/
|
||||
public function getStats()
|
||||
public function getStats(): array
|
||||
{
|
||||
return $this->stats;
|
||||
}
|
||||
|
@ -16,90 +16,49 @@ namespace Mailgun\Model\Stats;
|
||||
*/
|
||||
final class TotalResponseItem
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $time;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $accepted;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $delivered;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $failed;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $complained;
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public static function create(array $data)
|
||||
public static function create(array $data): self
|
||||
{
|
||||
return new self(
|
||||
isset($data['time']) ? new \DateTime($data['time']) : null,
|
||||
isset($data['accepted']) ? $data['accepted'] : [],
|
||||
isset($data['delivered']) ? $data['delivered'] : [],
|
||||
isset($data['failed']) ? $data['failed'] : [],
|
||||
isset($data['complained']) ? $data['complained'] : []
|
||||
);
|
||||
$model = new self();
|
||||
$model->time = isset($data['time']) ? new \DateTimeImmutable($data['time']) : null;
|
||||
$model->accepted = $data['accepted'] ?? [];
|
||||
$model->delivered = $data['delivered'] ?? [];
|
||||
$model->failed = $data['failed'] ?? [];
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getTime()
|
||||
public function getTime(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAccepted()
|
||||
public function getAccepted(): array
|
||||
{
|
||||
return $this->accepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDelivered()
|
||||
public function getDelivered(): array
|
||||
{
|
||||
return $this->delivered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFailed()
|
||||
public function getFailed(): array
|
||||
{
|
||||
return $this->failed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getComplained()
|
||||
public function getComplained(): array
|
||||
{
|
||||
return $this->complained;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user