1 | <?php |
||
2 | |||
3 | namespace Da\Mailer\Mail\Dto; |
||
4 | |||
5 | use Symfony\Component\Mime\Address; |
||
6 | |||
7 | class EmailAddress |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | private string $email; |
||
13 | /** |
||
14 | * @var string|null |
||
15 | */ |
||
16 | private ?string $name; |
||
17 | |||
18 | /** |
||
19 | * @param string $email |
||
20 | * @param string|null $name |
||
21 | */ |
||
22 | private function __construct(string $email, ?string $name = null) |
||
23 | { |
||
24 | $this->email = $email; |
||
25 | $this->name = $name; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param string $email |
||
30 | * @param string|null $name |
||
31 | * @return static |
||
32 | */ |
||
33 | public static function make(string $email, ?string $name = null): self |
||
34 | { |
||
35 | return new self($email, $name); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getEmail(): string |
||
42 | { |
||
43 | return $this->email; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return string|null |
||
48 | */ |
||
49 | public function getName(): ?string |
||
50 | { |
||
51 | return $this->name; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return Address |
||
56 | */ |
||
57 | public function parseToMailer(): Address |
||
58 | { |
||
59 | return new Address($this->getEmail(), $this->getName()); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
60 | } |
||
61 | } |
||
62 |