<?php

namespace App\ValueObjects;

class EmailAddress {
    private string $value;
    public static function fromString(string $value) : EmailAddress {
        if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
            throw new \InvalidArgumentException("Invalid email address: $value");
        }

        $emailAddress = new EmailAddress();
        $emailAddress->setValue($value);
        return $emailAddress;
    }

    public function getValue(): string
    {
        return $this->value;
    }

    public function setValue(string $value): void
    {
        $this->value = $value;
    }
}
