Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.74% covered (success)
94.74%
18 / 19
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ClientInstance
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
3 / 3
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%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 toArray
100.00% covered (success)
100.00%
8 / 8
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\Instance\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Client Instance Domain Model representing a connected remote client application.
13 *
14 * @package App\Core\Instance\Domain\Model
15 */
16final readonly class ClientInstance
17{
18    /**
19     * ClientInstance constructor.
20     *
21     * @param int $id Unique instance identifier.
22     * @param string $name Display name of the instance.
23     * @param string $environment Environment type (production, staging, dev).
24     * @param string $apiBaseUrl Base REST API URL (e.g. https://app-client.ammonly.com/api/v1).
25     * @param string $apiBearerToken Bearer authentication token for remote REST API.
26     * @param bool $isActive Active status of the instance.
27     * @param string|null $description Optional description notes.
28     */
29    public function __construct(
30        public int $id,
31        public string $name,
32        public string $environment,
33        public string $apiBaseUrl,
34        public string $apiBearerToken,
35        public bool $isActive = true,
36        public ?string $description = null
37    ) {
38    }
39
40    /**
41     * Creates domain model from database row array.
42     *
43     * @param array<string, mixed> $row Database record row.
44     * @return self New instance domain model.
45     */
46    public static function fromRow(array $row): self
47    {
48        return new self(
49            (int) ($row['id'] ?? 0),
50            (string) ($row['name'] ?? ''),
51            (string) ($row['environment'] ?? 'production'),
52            (string) ($row['api_base_url'] ?? ''),
53            (string) ($row['api_bearer_token'] ?? ''),
54            (bool) ($row['is_active'] ?? true),
55            isset($row['description']) ? (string) $row['description'] : null
56        );
57    }
58
59    /**
60     * Converts model to array for JSON serialization.
61     *
62     * @return array<string, mixed> Key-value pair array.
63     */
64    public function toArray(): array
65    {
66        return [
67            'id' => $this->id,
68            'name' => $this->name,
69            'environment' => $this->environment,
70            'api_base_url' => $this->apiBaseUrl,
71            'is_active' => $this->isActive,
72            'description' => $this->description,
73        ];
74    }
75}