Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
InstallerInputDto
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
2
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
 fromArray
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
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\Core\Installer\Dto;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Data Transfer Object for Console System Installation Parameters.
13 *
14 * @package App\Core\Installer\Dto
15 */
16final readonly class InstallerInputDto
17{
18    /**
19     * InstallerInputDto constructor.
20     *
21     * @param string $profile Application profile: 'admin' or 'client'.
22     * @param string $dbHost Database hostname or IP address.
23     * @param int $dbPort Database TCP port (e.g. 3306).
24     * @param string $dbName Target database schema name.
25     * @param string $dbUser Database username.
26     * @param string $dbPass Database password.
27     * @param string $adminEmail Super-administrator email address.
28     * @param string $adminPassword Super-administrator initial password.
29     * @param bool $withOptional Whether to load optional dictionary records.
30     * @param bool $withDemo Whether to include demo and testing datasets.
31     */
32    public function __construct(
33        public string $profile = 'admin',
34        public string $dbHost = '127.0.0.1',
35        public int $dbPort = 3306,
36        public string $dbName = 'ammonly_admin',
37        public string $dbUser = 'root',
38        public string $dbPass = '',
39        public string $adminEmail = 'help@ammonly.com',
40        public string $adminPassword = '',
41        public bool $withOptional = false,
42        public bool $withDemo = false
43    ) {
44    }
45
46    /**
47     * Creates DTO from associative array.
48     *
49     * @param array<string, mixed> $data
50     */
51    public static function fromArray(array $data): self
52    {
53        return new self(
54            profile: (string) ($data['profile'] ?? 'admin'),
55            dbHost: (string) ($data['dbHost'] ?? '127.0.0.1'),
56            dbPort: (int) ($data['dbPort'] ?? 3306),
57            dbName: (string) ($data['dbName'] ?? 'ammonly_admin'),
58            dbUser: (string) ($data['dbUser'] ?? 'root'),
59            dbPass: (string) ($data['dbPass'] ?? ''),
60            adminEmail: (string) ($data['adminEmail'] ?? 'help@ammonly.com'),
61            adminPassword: (string) ($data['adminPassword'] ?? ''),
62            withOptional: (bool) ($data['withOptional'] ?? false),
63            withDemo: (bool) ($data['withDemo'] ?? false)
64        );
65    }
66}