refactor: mail interfaces
All checks were successful
Build Test / build (pull_request) Successful in 12s
JS Unit Tests / test (pull_request) Successful in 11s
PHP Unit Tests / test (pull_request) Successful in 39s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-14 22:54:51 -04:00
parent d6005246dc
commit f3c882454d
24 changed files with 583 additions and 962 deletions

View File

@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace KTXF\Mail\Collection;
use KTXF\Resource\Identifier\CollectionIdentifier;
use KTXF\Resource\Provider\Node\NodeBaseAbstract;
/**
@@ -20,8 +21,13 @@ use KTXF\Resource\Provider\Node\NodeBaseAbstract;
*/
abstract class CollectionBase extends NodeBaseAbstract implements CollectionBaseInterface {
protected string $type = 'mail.collection';
protected CollectionPropertiesBaseAbstract $properties;
protected function nodeIdentifier(): CollectionIdentifier {
return new CollectionIdentifier($this->data[static::PROPERTY_PROVIDER], $this->data[static::PROPERTY_SERVICE], (string) $this->data[static::PROPERTY_IDENTIFIER]);
}
/**
* @inheritDoc
*/

View File

@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace KTXF\Mail\Collection;
use KTXF\Resource\Identifier\CollectionIdentifier;
use KTXF\Resource\Provider\Node\NodeMutableAbstract;
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
@@ -23,6 +24,10 @@ abstract class CollectionMutableAbstract extends NodeMutableAbstract implements
protected CollectionPropertiesMutableAbstract $properties;
protected function nodeIdentifier(): CollectionIdentifier {
return new CollectionIdentifier($this->data[static::PROPERTY_PROVIDER], $this->data[static::PROPERTY_SERVICE], $this->data[static::PROPERTY_IDENTIFIER]);
}
/**
* @inheritDoc
*/

View File

@@ -20,49 +20,47 @@ use KTXF\Resource\Provider\Node\NodePropertiesBaseAbstract;
*/
abstract class CollectionPropertiesBaseAbstract extends NodePropertiesBaseAbstract implements CollectionPropertiesBaseInterface {
public const JSON_TYPE = CollectionPropertiesBaseInterface::JSON_TYPE;
/**
* @inheritDoc
*/
public function total(): int {
return $this->data['total'] ?? 0;
return $this->data[static::PROPERTY_TOTAL] ?? 0;
}
/**
* @inheritDoc
*/
public function unread(): int {
return $this->data['unread'] ?? 0;
return $this->data[static::PROPERTY_UNREAD] ?? 0;
}
/**
* @inheritDoc
*/
public function getLabel(): string {
return $this->data['label'] ?? '';
return $this->data[static::PROPERTY_LABEL] ?? '';
}
/**
* @inheritDoc
*/
public function getRole(): CollectionRoles {
return isset($this->data['role'])
? ($this->data['role'] instanceof CollectionRoles ? $this->data['role'] : CollectionRoles::from($this->data['role']))
: CollectionRoles::Custom;
return isset($this->data[static::PROPERTY_ROLE])
? ($this->data[static::PROPERTY_ROLE] instanceof CollectionRoles ? $this->data[static::PROPERTY_ROLE] : CollectionRoles::from($this->data[static::PROPERTY_ROLE]))
: CollectionRoles::None;
}
/**
* @inheritDoc
*/
public function getRank(): int {
return $this->data['rank'] ?? 0;
return $this->data[static::PROPERTY_RANK] ?? 0;
}
/**
* @inheritDoc
*/
public function getSubscription(): bool {
return $this->data['subscribed'] ?? false;
return $this->data[static::PROPERTY_SUBSCRIPTION] ?? false;
}
}

View File

@@ -13,13 +13,12 @@ use KTXF\Resource\Provider\Node\NodePropertiesBaseInterface;
interface CollectionPropertiesBaseInterface extends NodePropertiesBaseInterface {
public const JSON_TYPE = 'mail.collection';
public const JSON_PROPERTY_TOTAL = 'total';
public const JSON_PROPERTY_UNREAD = 'unread';
public const JSON_PROPERTY_LABEL = 'label';
public const JSON_PROPERTY_ROLE = 'role';
public const JSON_PROPERTY_RANK = 'rank';
public const JSON_PROPERTY_SUBSCRIPTION = 'subscription';
public const PROPERTY_TOTAL = 'total';
public const PROPERTY_UNREAD = 'unread';
public const PROPERTY_LABEL = 'label';
public const PROPERTY_ROLE = 'role';
public const PROPERTY_RANK = 'rank';
public const PROPERTY_SUBSCRIPTION = 'subscription';
public function total(): int;

View File

@@ -16,8 +16,6 @@ use KTXF\Resource\Provider\Node\NodePropertiesMutableAbstract;
*/
abstract class CollectionPropertiesMutableAbstract extends CollectionPropertiesBaseAbstract implements CollectionPropertiesMutableInterface {
public const JSON_TYPE = CollectionPropertiesBaseInterface::JSON_TYPE;
/**
* @inheritDoc
*/
@@ -35,7 +33,7 @@ abstract class CollectionPropertiesMutableAbstract extends CollectionPropertiesB
* @inheritDoc
*/
public function setLabel(string $value): static {
$this->data['label'] = $value;
$this->data[self::PROPERTY_LABEL] = $value;
return $this;
}
@@ -43,7 +41,7 @@ abstract class CollectionPropertiesMutableAbstract extends CollectionPropertiesB
* @inheritDoc
*/
public function setRole(CollectionRoles $value): static {
$this->data['role'] = $value;
$this->data[self::PROPERTY_ROLE] = $value;
return $this;
}
@@ -51,7 +49,7 @@ abstract class CollectionPropertiesMutableAbstract extends CollectionPropertiesB
* @inheritDoc
*/
public function setRank(int $value): static {
$this->data['rank'] = $value;
$this->data[self::PROPERTY_RANK] = $value;
return $this;
}
@@ -59,7 +57,7 @@ abstract class CollectionPropertiesMutableAbstract extends CollectionPropertiesB
* @inheritDoc
*/
public function setSubscription(bool $value): static {
$this->data['subscription'] = $value;
$this->data[self::PROPERTY_SUBSCRIPTION] = $value;
return $this;
}
}

View File

@@ -13,8 +13,6 @@ use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
interface CollectionPropertiesMutableInterface extends CollectionPropertiesBaseInterface, NodePropertiesMutableInterface {
public const JSON_TYPE = CollectionPropertiesBaseInterface::JSON_TYPE;
public function setLabel(string $value);
public function setRole(CollectionRoles $value): static;