refactor: message object properties
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -25,16 +25,6 @@ class Address implements AddressInterface {
|
||||
private ?string $name = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return array_filter([
|
||||
self::JSON_PROPERTY_ADDRESS => $this->address,
|
||||
self::JSON_PROPERTY_LABEL => $this->name,
|
||||
], fn($v) => $v !== null && $v !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Address from a formatted string
|
||||
*
|
||||
@@ -66,17 +56,34 @@ class Address implements AddressInterface {
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param array $data Array with 'address' and optional 'name' keys
|
||||
* @param array<address: string, label: string|null> $data
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromArray(array $data): self {
|
||||
return new self(
|
||||
$data[self::JSON_PROPERTY_ADDRESS] ?? $data['address'] ?? '',
|
||||
$data[self::JSON_PROPERTY_LABEL] ?? $data['name'] ?? null,
|
||||
$data[self::PROPERTY_ADDRESS] ?? $data['address'] ?? '',
|
||||
$data[self::PROPERTY_LABEL] ?? $data['label'] ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return array_filter([
|
||||
self::PROPERTY_ADDRESS => $this->address,
|
||||
self::PROPERTY_LABEL => $this->name,
|
||||
], fn($v) => $v !== null && $v !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): array {
|
||||
return $this->jsonSerialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user