Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DocumentVersion | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSnapshotField | |
100.00% |
1 / 1 |
|
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\Documents\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Domain model representing a point-in-time version snapshot of a Document. |
| 13 | * |
| 14 | * @package App\Modules\Documents\Domain\Model |
| 15 | */ |
| 16 | final readonly class DocumentVersion |
| 17 | { |
| 18 | /** |
| 19 | * DocumentVersion constructor. |
| 20 | * |
| 21 | * @param int $id Unique version record identifier. |
| 22 | * @param int $documentId Parent document record identifier. |
| 23 | * @param string $versionNumber Semantic version string (e.g. 1.0, 1.1, 2.0). |
| 24 | * @param string $versionType Version increment type: initial, minor, major. |
| 25 | * @param string|null $versionTag Optional semantic tag or milestone name. |
| 26 | * @param string|null $changeSummary Detailed description of changes made in this version. |
| 27 | * @param array<string, mixed> $snapshotData Full JSON serialized document snapshot. |
| 28 | * @param bool $isCurrent Whether this is the currently active version. |
| 29 | * @param int $createdBy User identifier who authored the revision. |
| 30 | * @param string $createdAt Version timestamp. |
| 31 | */ |
| 32 | public function __construct( |
| 33 | public int $id, |
| 34 | public int $documentId, |
| 35 | public string $versionNumber, |
| 36 | public string $versionType = 'minor', |
| 37 | public ?string $versionTag = null, |
| 38 | public ?string $changeSummary = null, |
| 39 | public array $snapshotData = [], |
| 40 | public bool $isCurrent = false, |
| 41 | public int $createdBy = 1, |
| 42 | public string $createdAt = '', |
| 43 | ) { |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Extracts a specific field value from the snapshot data. |
| 48 | * |
| 49 | * @param string $field Key of the field to retrieve. |
| 50 | * @param mixed $default Fallback value if field is not present in snapshot. |
| 51 | * @return mixed Field value from snapshot or default. |
| 52 | */ |
| 53 | public function getSnapshotField(string $field, mixed $default = null): mixed |
| 54 | { |
| 55 | return $this->snapshotData[$field] ?? $default; |
| 56 | } |
| 57 | } |