Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ContactMessageData | |
100.00% |
21 / 21 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromRow | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Contact\Data; |
| 6 | |
| 7 | use App\Support\Row; |
| 8 | |
| 9 | final readonly class ContactMessageData |
| 10 | { |
| 11 | public function __construct( |
| 12 | public int $contactMessageId, |
| 13 | // Null for public (logged-out) submissions; senderName/senderEmail |
| 14 | // carry the reply-to identity in that case. |
| 15 | public ?int $userId, |
| 16 | public string $subject, |
| 17 | public string $message, |
| 18 | public string $status, |
| 19 | public string $createdAt, |
| 20 | public ?string $senderName = null, |
| 21 | public ?string $senderEmail = null, |
| 22 | ) {} |
| 23 | |
| 24 | /** |
| 25 | * @param array<mixed> $data |
| 26 | */ |
| 27 | public static function fromRow(array $data): self |
| 28 | { |
| 29 | return new self( |
| 30 | contactMessageId: Row::int($data, 'contactMessageId'), |
| 31 | userId: Row::nullableInt($data, 'userId'), |
| 32 | subject: Row::string($data, 'subject'), |
| 33 | message: Row::string($data, 'message'), |
| 34 | status: Row::string($data, 'status'), |
| 35 | createdAt: Row::string($data, 'createdAt'), |
| 36 | senderName: Row::nullableString($data, 'senderName'), |
| 37 | senderEmail: Row::nullableString($data, 'senderEmail'), |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @return array<string, mixed> |
| 43 | */ |
| 44 | public function toArray(): array |
| 45 | { |
| 46 | return [ |
| 47 | 'contactMessageId' => $this->contactMessageId, |
| 48 | 'userId' => $this->userId, |
| 49 | 'subject' => $this->subject, |
| 50 | 'message' => $this->message, |
| 51 | 'status' => $this->status, |
| 52 | 'createdAt' => $this->createdAt, |
| 53 | 'senderName' => $this->senderName, |
| 54 | 'senderEmail' => $this->senderEmail, |
| 55 | ]; |
| 56 | } |
| 57 | } |