Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UserPreference
100.00% covered (success)
100.00%
9 / 9
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
 create
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\Preference\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Aggregate Root representing an individual user preference setting.
13 *
14 * Stores typed key-value preferences within a hierarchical scope.
15 *
16 * @package App\Core\Preference\Domain\Model
17 */
18final readonly class UserPreference
19{
20    /**
21     * UserPreference constructor.
22     *
23     * @param int|null        $id              Unique database record ID (null for new entity).
24     * @param PreferenceScope $scope           Scope identifying the user, device, module, and entity.
25     * @param string          $key             Preference key name.
26     * @param mixed           $value           Typed preference value.
27     * @param string|null     $createdAt       Creation timestamp string or null.
28     * @param string|null     $updatedAt       Update timestamp string or null.
29     */
30    public function __construct(
31        public ?int $id,
32        public PreferenceScope $scope,
33        public string $key,
34        public mixed $value,
35        public ?string $createdAt = null,
36        public ?string $updatedAt = null,
37    ) {
38    }
39
40    /**
41     * Creates a new UserPreference aggregate.
42     *
43     * @param PreferenceScope $scope Preference scope.
44     * @param string          $key   Preference key.
45     * @param mixed           $value Preference value.
46     * @return self New preference instance.
47     */
48    public static function create(PreferenceScope $scope, string $key, mixed $value): self
49    {
50        return new self(
51            id: null,
52            scope: $scope,
53            key: $key,
54            value: $value,
55            createdAt: null,
56            updatedAt: null,
57        );
58    }
59}