Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DavDevice | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| 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\Dav\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use DateTimeImmutable; |
| 12 | |
| 13 | /** |
| 14 | * DAV Device Domain Model. |
| 15 | * |
| 16 | * Represents an enrolled mobile or desktop synchronization device paired via unique sync token. |
| 17 | * |
| 18 | * @package App\Modules\Dav\Domain\Model |
| 19 | */ |
| 20 | final readonly class DavDevice |
| 21 | { |
| 22 | /** |
| 23 | * DavDevice constructor. |
| 24 | * |
| 25 | * @param int $id Primary database identifier. |
| 26 | * @param int $userId Owner user identifier. |
| 27 | * @param string $deviceName User-friendly label (e.g. iPhone 15 Pro, Work Laptop). |
| 28 | * @param string $deviceType Device platform ('ios', 'android', 'macos', 'other'). |
| 29 | * @param string $syncToken Secret unique device pairing token. |
| 30 | * @param DateTimeImmutable|null $lastSyncAt Last recorded synchronization timestamp. |
| 31 | * @param bool $isActive Whether the device pairing is currently active and allowed. |
| 32 | * @param DateTimeImmutable $createdAt Enrollment timestamp. |
| 33 | */ |
| 34 | public function __construct( |
| 35 | public int $id, |
| 36 | public int $userId, |
| 37 | public string $deviceName, |
| 38 | public string $deviceType, |
| 39 | public string $syncToken, |
| 40 | public ?DateTimeImmutable $lastSyncAt, |
| 41 | public bool $isActive, |
| 42 | public DateTimeImmutable $createdAt |
| 43 | ) { |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Serializes device to associative array representation for API responses. |
| 48 | * |
| 49 | * @param string $baseUrl Base URL for configuration links. |
| 50 | * @return array<string, mixed> Serialized dictionary. |
| 51 | */ |
| 52 | public function toArray(string $baseUrl = ''): array |
| 53 | { |
| 54 | $setupUrl = rtrim($baseUrl, '/') . '/dav/setup/' . $this->syncToken; |
| 55 | $profileUrl = rtrim($baseUrl, '/') . '/dav/profile/' . $this->syncToken . '.mobileconfig'; |
| 56 | |
| 57 | return [ |
| 58 | 'id' => $this->id, |
| 59 | 'user_id' => $this->userId, |
| 60 | 'device_name' => $this->deviceName, |
| 61 | 'device_type' => $this->deviceType, |
| 62 | 'sync_token' => $this->syncToken, |
| 63 | 'setup_url' => $setupUrl, |
| 64 | 'profile_url' => $profileUrl, |
| 65 | 'last_sync_at' => $this->lastSyncAt?->format('Y-m-d H:i:s'), |
| 66 | 'is_active' => $this->isActive, |
| 67 | 'created_at' => $this->createdAt->format('Y-m-d H:i:s'), |
| 68 | ]; |
| 69 | } |
| 70 | } |