diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-10-13 18:27:10 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-10-14 11:15:17 +0300 |
commit | 6ecf51cf7d472ef375cd637b825702498d8931c8 (patch) | |
tree | 75b80cd0fe4a2d78a921ccb29c7f90f82994687a /lib/Address.php | |
parent | 868bc2917ebebb7b71d973ef6da3912ff0ae598c (diff) |
Mark immutable classes as immutable
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Address.php')
-rw-r--r-- | lib/Address.php | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/Address.php b/lib/Address.php index aaac62adf..af2e95028 100644 --- a/lib/Address.php +++ b/lib/Address.php @@ -29,6 +29,9 @@ namespace OCA\Mail; use Horde_Mail_Rfc822_Address; use JsonSerializable; +/** + * @psalm-immutable + */ class Address implements JsonSerializable { public const TYPE_FROM = 0; public const TYPE_TO = 1; @@ -38,16 +41,21 @@ class Address implements JsonSerializable { /** @var Horde_Mail_Rfc822_Address */ private $wrapped; - /** - * @param string $label - * @param string $email - */ - public function __construct($label, $email) { - $this->wrapped = new Horde_Mail_Rfc822_Address($email); + private function __construct(Horde_Mail_Rfc822_Address $wrapped) { + $this->wrapped = $wrapped; + } + + public static function fromHorde(Horde_Mail_Rfc822_Address $horde): self { + return new self($horde); + } + + public static function fromRaw($label, $email): self { + $wrapped = new Horde_Mail_Rfc822_Address($email); // If no label is set we use the email if ($label !== $email && $label !== null) { - $this->wrapped->personal = $label; + $wrapped->personal = $label; } + return new self($wrapped); } /** |