Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MailServer
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fromRow
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Mail\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Mail Server Infrastructure Node Aggregate Model.
13 *
14 * Encapsulates incoming (IMAP) and outgoing (SMTP) server hostnames, ports,
15 * TLS policies, and domain verification statuses (SPF, DKIM, DMARC).
16 *
17 * @package App\Modules\Mail\Domain\Model
18 */
19final readonly class MailServer
20{
21    /**
22     * MailServer constructor.
23     *
24     * @param int         $id                  Primary ID.
25     * @param string      $name                Server display name.
26     * @param string      $code                Unique machine code.
27     * @param string      $imapHost            IMAP server hostname.
28     * @param int         $imapPort            IMAP port (default 993).
29     * @param string      $imapEncryption      IMAP encryption (ssl, tls, starttls, none).
30     * @param string      $smtpHost            SMTP server hostname.
31     * @param int         $smtpPort            SMTP port (default 465).
32     * @param string      $smtpEncryption      SMTP encryption (ssl, tls, starttls, none).
33     * @param bool        $requireTls          Whether TLS is mandatory.
34     * @param bool        $allowSelfSigned     Whether self-signed certificates are accepted.
35     * @param bool        $isPublicForClients  Whether accessible to Client profile.
36     * @param bool        $isDefault           Whether system default server.
37     * @param string      $spfStatus           SPF record check status.
38     * @param string      $dkimStatus          DKIM signature check status.
39     * @param string      $dmarcStatus         DMARC policy status.
40     * @param string|null $description         Optional server notes.
41     * @param bool        $isActive            Active status flag.
42     */
43    public function __construct(
44        public int $id,
45        public string $name,
46        public string $code,
47        public string $imapHost,
48        public int $imapPort,
49        public string $imapEncryption,
50        public string $smtpHost,
51        public int $smtpPort,
52        public string $smtpEncryption,
53        public bool $requireTls = true,
54        public bool $allowSelfSigned = false,
55        public bool $isPublicForClients = true,
56        public bool $isDefault = false,
57        public string $spfStatus = 'valid',
58        public string $dkimStatus = 'valid',
59        public string $dmarcStatus = 'valid',
60        public ?string $description = null,
61        public bool $isActive = true
62    ) {
63    }
64
65    /**
66     * Instantiates MailServer from database row.
67     *
68     * @param array<string, mixed> $row Database associative record.
69     * @return self Populated MailServer instance.
70     */
71    public static function fromRow(array $row): self
72    {
73        return new self(
74            id: (int)($row['id'] ?? 0),
75            name: (string)($row['name'] ?? ''),
76            code: (string)($row['code'] ?? ''),
77            imapHost: (string)($row['imap_host'] ?? ''),
78            imapPort: (int)($row['imap_port'] ?? 993),
79            imapEncryption: (string)($row['imap_encryption'] ?? 'ssl'),
80            smtpHost: (string)($row['smtp_host'] ?? ''),
81            smtpPort: (int)($row['smtp_port'] ?? 465),
82            smtpEncryption: (string)($row['smtp_encryption'] ?? 'ssl'),
83            requireTls: (bool)($row['require_tls'] ?? true),
84            allowSelfSigned: (bool)($row['allow_self_signed'] ?? false),
85            isPublicForClients: (bool)($row['is_public_for_clients'] ?? true),
86            isDefault: (bool)($row['is_default'] ?? false),
87            spfStatus: (string)($row['spf_status'] ?? 'valid'),
88            dkimStatus: (string)($row['dkim_status'] ?? 'valid'),
89            dmarcStatus: (string)($row['dmarc_status'] ?? 'valid'),
90            description: isset($row['description']) && (string)$row['description'] !== ''
91                ? (string)$row['description']
92                : null,
93            isActive: (bool)($row['is_active'] ?? true)
94        );
95    }
96}