Full implemantation
This commit is contained in:
@ -4,12 +4,15 @@ namespace ProVM\Emails\Model;
|
||||
use DateTimeInterface;
|
||||
use ProVM\Common\Define\Model;
|
||||
use ProVM\Common\Exception\Database\BlankResult;
|
||||
use ProVM\Common\Exception\EmptyMailbox;
|
||||
use ProVM\Common\Exception\Mailbox\Stateless;
|
||||
use Safe\DateTimeImmutable;
|
||||
|
||||
class Mailbox implements Model
|
||||
{
|
||||
protected int $id;
|
||||
protected string $name;
|
||||
protected int $validity;
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
@ -19,6 +22,10 @@ class Mailbox implements Model
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
public function getValidity(): int
|
||||
{
|
||||
return $this->validity;
|
||||
}
|
||||
|
||||
public function setId(int $id): Mailbox
|
||||
{
|
||||
@ -30,6 +37,11 @@ class Mailbox implements Model
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
public function setValidity(int $uidvalidity): Mailbox
|
||||
{
|
||||
$this->validity = $uidvalidity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected \ProVM\Emails\Repository\State\Mailbox $stateRepository;
|
||||
|
||||
@ -68,19 +80,31 @@ class Mailbox implements Model
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function lastState(): State\Mailbox
|
||||
{
|
||||
if (count($this->getStates()) === 0) {
|
||||
throw new Stateless($this);
|
||||
}
|
||||
return $this->getStates()[array_key_last($this->getStates())];
|
||||
}
|
||||
public function lastChecked(): ?DateTimeInterface
|
||||
{
|
||||
if (count($this->getStates()) == 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->getStates()[array_key_last($this->getStates())]->getDateTime();
|
||||
return $this->lastState()->getDateTime();
|
||||
}
|
||||
public function lastCount(): int
|
||||
{
|
||||
if (count($this->getStates()) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return $this->getStates()[array_key_last($this->getStates())]->getCount();
|
||||
return $this->lastState()->getCount();
|
||||
}
|
||||
public function lastPosition(): int
|
||||
{
|
||||
$state = $this->lastState()->getUIDs();
|
||||
return array_key_last($state);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
@ -88,6 +112,7 @@ class Mailbox implements Model
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'name' => $this->getName(),
|
||||
//'validity' => $this->getValidity(),
|
||||
'last_checked' => [
|
||||
'date' => $this->lastChecked() ?? 'never',
|
||||
'count' => $this->lastCount() ?? 0
|
||||
|
Reference in New Issue
Block a user