| Total Complexity | 7 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 20 | class Message implements \Stringable |
||
| 21 | { |
||
| 22 | public function __construct(private string $subject, private ?string $body = null) |
||
| 23 | { |
||
| 24 | } |
||
| 25 | |||
| 26 | public function __toString(): string |
||
| 27 | { |
||
| 28 | $full = $this->subject; |
||
| 29 | |||
| 30 | if (!empty($this->body)) { |
||
| 31 | $full .= "\n\n".$this->body; |
||
| 32 | } |
||
| 33 | |||
| 34 | return $full; |
||
| 35 | } |
||
| 36 | |||
| 37 | public static function fromString(string $message): self |
||
| 38 | { |
||
| 39 | $data = \explode("\n\n", $message, 2); |
||
| 40 | |||
| 41 | return new self($data[0] ?? '', $data[2] ?? null); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function getSubject(): string |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getBody(): ?string |
||
| 50 | { |
||
| 54 |