Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
DataChange | |
0.00% |
0 / 9 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
reHash | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHash | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toArray | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package Modules\Admin\Models |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace Modules\Admin\Models; |
16 | |
17 | /** |
18 | * Data change model. |
19 | * |
20 | * @package Modules\Admin\Models |
21 | * @license OMS License 2.0 |
22 | * @link https://jingga.app |
23 | * @since 1.0.0 |
24 | */ |
25 | class DataChange |
26 | { |
27 | /** |
28 | * Id |
29 | * |
30 | * @var int |
31 | * @since 1.0.0 |
32 | */ |
33 | public int $id = 0; |
34 | |
35 | /** |
36 | * Hash |
37 | * |
38 | * @var string |
39 | * @since 1.0.0 |
40 | */ |
41 | protected string $hash = ''; |
42 | |
43 | /** |
44 | * Data for the change |
45 | * |
46 | * @var string |
47 | * @since 1.0.0 |
48 | */ |
49 | public string $data = ''; |
50 | |
51 | /** |
52 | * Change type |
53 | * |
54 | * @var string |
55 | * @since 1.0.0 |
56 | */ |
57 | public string $type = ''; |
58 | |
59 | /** |
60 | * Created by account |
61 | * |
62 | * @var int |
63 | * @since 1.0.0 |
64 | */ |
65 | public int $createdBy = 0; |
66 | |
67 | /** |
68 | * Created at |
69 | * |
70 | * @var \DateTimeImmutable |
71 | * @since 1.0.0 |
72 | */ |
73 | public \DateTimeImmutable $createdAt; |
74 | |
75 | /** |
76 | * Constructor. |
77 | * |
78 | * @since 1.0.0 |
79 | */ |
80 | public function __construct() |
81 | { |
82 | $this->createdAt = new \DateTimeImmutable('now'); |
83 | $this->reHash(); |
84 | } |
85 | |
86 | /** |
87 | * Create hash for data change as identifier |
88 | * |
89 | * @return void |
90 | * |
91 | * @since 1.0.0 |
92 | */ |
93 | public function reHash() : void |
94 | { |
95 | $this->hash = \bin2hex(\random_bytes(16)); |
96 | } |
97 | |
98 | /** |
99 | * Get hash |
100 | * |
101 | * @return string |
102 | * |
103 | * @since 1.0.0 |
104 | */ |
105 | public function getHash() : string |
106 | { |
107 | return $this->hash; |
108 | } |
109 | |
110 | /** |
111 | * {@inheritdoc} |
112 | */ |
113 | public function toArray() : array |
114 | { |
115 | return [ |
116 | 'id' => $this->id, |
117 | 'data' => $this->data, |
118 | ]; |
119 | } |
120 | |
121 | /** |
122 | * {@inheritdoc} |
123 | */ |
124 | public function jsonSerialize() : mixed |
125 | { |
126 | return $this->toArray(); |
127 | } |
128 | } |