Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| SystemMailbox | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromRow | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Mail\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * System Service Mailbox Model. |
| 13 | * |
| 14 | * Dedicated mailboxes for automated processes (tickets intake scanner, bounce handling). |
| 15 | * |
| 16 | * @package App\Modules\Mail\Domain\Model |
| 17 | */ |
| 18 | final readonly class SystemMailbox |
| 19 | { |
| 20 | /** |
| 21 | * SystemMailbox constructor. |
| 22 | * |
| 23 | * @param int $id Primary ID. |
| 24 | * @param string $name Display name. |
| 25 | * @param string $mailboxType Type: scanner, bounce, audit, noreply. |
| 26 | * @param int $mailServerId Associated MailServer ID. |
| 27 | * @param string $email Email address. |
| 28 | * @param string $username Login username. |
| 29 | * @param string $password AEAD encrypted password. |
| 30 | * @param string|null $targetModule Target CRM module (e.g. tickets). |
| 31 | * @param int $scanFrequencyMinutes Scanning interval in minutes. |
| 32 | * @param string|null $lastScanAt Last scan timestamp. |
| 33 | * @param bool $isActive Active flag. |
| 34 | */ |
| 35 | public function __construct( |
| 36 | public int $id, |
| 37 | public string $name, |
| 38 | public string $mailboxType, |
| 39 | public int $mailServerId, |
| 40 | public string $email, |
| 41 | public string $username, |
| 42 | public string $password, |
| 43 | public ?string $targetModule = 'tickets', |
| 44 | public int $scanFrequencyMinutes = 5, |
| 45 | public ?string $lastScanAt = null, |
| 46 | public bool $isActive = true |
| 47 | ) { |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Instantiates SystemMailbox from database row. |
| 52 | * |
| 53 | * @param array<string, mixed> $row Database row. |
| 54 | * @return self Populated instance. |
| 55 | */ |
| 56 | public static function fromRow(array $row): self |
| 57 | { |
| 58 | return new self( |
| 59 | id: (int)($row['id'] ?? 0), |
| 60 | name: (string)($row['name'] ?? ''), |
| 61 | mailboxType: (string)($row['mailbox_type'] ?? 'scanner'), |
| 62 | mailServerId: (int)($row['mail_server_id'] ?? 0), |
| 63 | email: (string)($row['email'] ?? ''), |
| 64 | username: (string)($row['username'] ?? ''), |
| 65 | password: (string)($row['password'] ?? ''), |
| 66 | targetModule: isset($row['target_module']) && (string)$row['target_module'] !== '' |
| 67 | ? (string)$row['target_module'] |
| 68 | : null, |
| 69 | scanFrequencyMinutes: (int)($row['scan_frequency_minutes'] ?? 5), |
| 70 | lastScanAt: isset($row['last_scan_at']) ? (string)$row['last_scan_at'] : null, |
| 71 | isActive: (bool)($row['is_active'] ?? true) |
| 72 | ); |
| 73 | } |
| 74 | } |