Refactor Tag models to php7 code (#548)

* Refactor models to php7 code

* return model from create method fix
This commit is contained in:
Radoje Albijanic 2019-01-22 18:38:44 +01:00 committed by Tobias Nyholm
parent 259d91cb75
commit 272033dff2
8 changed files with 54 additions and 179 deletions

View File

@ -22,10 +22,6 @@ final class CountryResponse implements ApiResponse
* @var array [locale => data[]]
*/
private $countries;
/**
* @var string
*/
private $tag;
private function __construct()

View File

@ -18,31 +18,21 @@ use Mailgun\Model\ApiResponse;
*/
final class DeleteResponse implements ApiResponse
{
/**
* @var string
*/
private $message;
/**
* @param string $message
*/
private function __construct($message)
private function __construct()
{
$this->message = $message;
}
/**
* @return DeleteResponse
*/
public static function create(array $data)
public static function create(array $data): self
{
return new self($data['message']);
$model = new self();
$model->message = $data['message'] ?? '';
return $model;
}
/**
* @return string
*/
public function getMessage()
public function getMessage(): string
{
return $this->message;
}

View File

@ -22,10 +22,6 @@ final class DeviceResponse implements ApiResponse
* @var array [name => data[]]
*/
private $devices;
/**
* @var string
*/
private $tag;
private function __construct()

View File

@ -11,9 +11,9 @@ declare(strict_types=1);
namespace Mailgun\Model\Tag;
use Mailgun\Model\ApiResponse;
use Mailgun\Model\PaginationResponse;
use Mailgun\Model\PagingProvider;
use Mailgun\Model\ApiResponse;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
@ -27,32 +27,29 @@ final class IndexResponse implements ApiResponse, PagingProvider
*/
private $items;
/**
* @param Tag[] $items
*/
private function __construct(array $items, array $paging)
private function __construct()
{
$this->items = $items;
$this->paging = $paging;
}
/**
* @return IndexResponse
*/
public static function create(array $data)
public static function create(array $data): self
{
$items = [];
foreach ($data['items'] as $item) {
$items[] = Tag::create($item);
}
return new self($items, $data['paging']);
$model = new self();
$model->items = $items;
$model->paging = $data['paging'];
return $model;
}
/**
* @return Tag[]
*/
public function getItems()
public function getItems(): array
{
return $this->items;
}

View File

@ -22,10 +22,6 @@ final class ProviderResponse implements ApiResponse
* @var array [name => data[]]
*/
private $providers;
/**
* @var string
*/
private $tag;
private function __construct()

View File

@ -18,110 +18,57 @@ use Mailgun\Model\ApiResponse;
*/
final class StatisticsResponse implements ApiResponse
{
/**
* @var string
*/
private $tag;
/**
* @var string
*/
private $description;
/**
* @var string
*/
private $resolution;
/**
* @var \DateTime
*/
private $start;
/**
* @var \DateTime
*/
private $end;
/**
* @var array
*/
private $stats;
/**
* @param string $tag
* @param string $description
* @param string $resolution
*/
private function __construct($tag, $description, \DateTime $start, \DateTime $end, $resolution, array $stats)
private function __construct()
{
$this->tag = $tag;
$this->description = $description;
$this->resolution = $resolution;
$this->start = $start;
$this->end = $end;
$this->stats = $stats;
}
/**
* @return StatisticsResponse
*/
public static function create(array $data)
public static function create(array $data): self
{
return new self(
$data['tag'],
$data['description'],
new \DateTime($data['start']),
new \DateTime($data['end']),
$data['resolution'],
$data['stats']
);
$model = new self();
$model->tag = $data['tag'] ?? '';
$model->description = $data['description'] ?? '';
$model->resolution = $data['resolution'] ?? null;
$model->stats = $data['stats'] ?? [];
$model->start = isset($data['start']) ? new \DateTimeImmutable($data['start']) : null;
$model->end = isset($data['end']) ? new \DateTimeImmutable($data['end']) : null;
return $model;
}
/**
* @return string
*/
public function getTag()
public function getTag(): string
{
return $this->tag;
}
/**
* @return string
*/
public function getDescription()
public function getDescription(): string
{
return $this->description;
}
/**
* @return string
*/
public function getResolution()
public function getResolution(): ?string
{
return $this->resolution;
}
/**
* @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 array
*/
public function getStats()
public function getStats(): array
{
return $this->stats;
}

View File

@ -13,79 +13,43 @@ namespace Mailgun\Model\Tag;
class Tag
{
/**
* @var string
*/
private $tag;
/**
* @var string
*/
private $description;
/**
* @var \DateTime
*/
private $firstSeen;
/**
* @var \DateTime
*/
private $lastSeen;
/**
* @param string $tag
* @param string $description
* @param \DateTime $firstSeen
* @param \DateTime $lastSeen
*/
private function __construct($tag, $description, \DateTime $firstSeen = null, \DateTime $lastSeen = null)
private function __construct()
{
$this->tag = $tag;
$this->description = $description;
$this->firstSeen = $firstSeen;
$this->lastSeen = $lastSeen;
}
/**
* @return Tag
*/
public static function create(array $data)
public static function create(array $data): self
{
$firstSeen = isset($data['first-seen']) ? new \DateTime($data['first-seen']) : null;
$lastSeen = isset($data['last-seen']) ? new \DateTime($data['last-seen']) : null;
$model = new self();
return new self($data['tag'], $data['description'], $firstSeen, $lastSeen);
$model->tag = $data['tag'] ?? '';
$model->description = $data['description'] ?? '';
$model->firstSeen = isset($data['first-seen']) ? new \DateTimeImmutable($data['first-seen']) : null;
$model->lastSeen = isset($data['last-seen']) ? new \DateTimeImmutable($data['last-seen']) : null;
return $model;
}
/**
* @return string
*/
public function getTag()
public function getTag(): string
{
return $this->tag;
}
/**
* @return string
*/
public function getDescription()
public function getDescription(): string
{
return $this->description;
}
/**
* @return \DateTime
*/
public function getFirstSeen()
public function getFirstSeen(): ?\DateTimeImmutable
{
return $this->firstSeen;
}
/**
* @return \DateTime
*/
public function getLastSeen()
public function getLastSeen(): ?\DateTimeImmutable
{
return $this->lastSeen;
}

View File

@ -18,31 +18,20 @@ use Mailgun\Model\ApiResponse;
*/
final class UpdateResponse implements ApiResponse
{
/**
* @var string
*/
private $message;
/**
* @param string $message
*/
private function __construct($message)
private function __construct()
{
$this->message = $message;
}
/**
* @return UpdateResponse
*/
public static function create(array $data)
public static function create(array $data): self
{
return new self($data['message']);
$model = new self();
$model->message = $data['message'] ?? '';
}
/**
* @return string
*/
public function getMessage()
public function getMessage(): string
{
return $this->message;
}