File tree Expand file tree Collapse file tree 3 files changed +65
-14
lines changed
Expand file tree Collapse file tree 3 files changed +65
-14
lines changed Original file line number Diff line number Diff line change 99final class Struct
1010{
1111 /**
12+
1213 * @var string
1314 */
1415 public string $ name ;
@@ -35,6 +36,7 @@ public function __construct(array $fields)
3536 }
3637
3738 /**
39+
3840 * Add a new field to the struct.
3941 *
4042 * Adds a field to the struct with its specified type and initializes it with a null value.
@@ -111,11 +113,13 @@ public function get(string $name): mixed
111113 }
112114
113115 /**
116+
114117 * Get all fields in the struct.
115118 *
116119 * Returns the entire set of fields in the struct along with their types and values.
117120 *
118121 * @return array<string, array{type: string, value: mixed}> The fields with their respective types and values.
122+
119123 */
120124 public function getFields (): array
121125 {
Original file line number Diff line number Diff line change 66
77final class Union
88{
9+ /**
10+ * @var mixed
11+ */
912 private mixed $ value ;
13+
14+ /**
15+ * @var array
16+ */
1017 private array $ allowedTypes ;
1118
19+ /**
20+ * @param array $allowedTypes
21+ */
1222 public function __construct (array $ allowedTypes )
1323 {
1424 $ this ->allowedTypes = $ allowedTypes ;
1525 }
1626
17- // Set a value of one of the allowed types
27+ /**
28+ * @param mixed $value
29+ * @return void
30+ */
1831 public function setValue (mixed $ value ): void
1932 {
2033 $ this ->validateType ($ value );
2134 $ this ->value = $ value ;
2235 }
2336
24- // Get the value
37+ /**
38+ * @return mixed
39+ */
2540 public function getValue (): mixed
2641 {
2742 return $ this ->value ;
2843 }
2944
30- // Validate that the value matches one of the allowed types
45+ /**
46+ * @param mixed $value
47+ * @return void
48+ */
3149 private function validateType (mixed $ value ): void
3250 {
3351 $ type = gettype ($ value );
Original file line number Diff line number Diff line change 2121use Nejcc \PhpDatatypes \Scalar \Integers \Unsigned \UInt32 ;
2222use Nejcc \PhpDatatypes \Scalar \Integers \Unsigned \UInt8 ;
2323
24+ /**
25+ * @param int $value
26+ * @return Int8
27+ */
2428function int8 (int $ value ): Int8
2529{
2630 return new Int8 ($ value );
2731}
2832
33+ /**
34+ * @param int $value
35+ * @return Int16
36+ */
2937function int16 (int $ value ): Int16
3038{
3139 return new Int16 ($ value );
3240}
3341
42+ /**
43+ * @param int $value
44+ * @return Int32
45+ */
3446function int32 (int $ value ): Int32
3547{
3648 return new Int32 ($ value );
3749}
3850
51+ /**
52+ * @param int $value
53+ * @return Int64
54+ */
3955function int64 (int $ value ): Int64
4056{
4157 return new Int64 ($ value );
4258}
4359
60+ /**
61+ * @param int $value
62+ * @return Int128
63+ */
4464function int128 (int $ value ): Int128
4565{
4666 return new Int128 ($ value );
4767}
4868
69+ /**
70+ * @param int $value
71+ * @return UInt8
72+ */
4973function uint8 (int $ value ): UInt8
5074{
5175 return new UInt8 ($ value );
5276}
5377
78+ /**
79+ * @param int $value
80+ * @return UInt16
81+ */
5482function uint16 (int $ value ): UInt16
5583{
5684 return new UInt16 ($ value );
5785}
5886
87+ /**
88+ * @param int $value
89+ * @return UInt32
90+ */
5991function uint32 (int $ value ): UInt32
6092{
6193 return new UInt32 ($ value );
6294}
6395
64- //
65- //function uint64(int $value): Int64
66- //{
67- // return new UInt64($value);
68- //}
69- //
70- //function uint128(int $value): Int128
71- //{
72- // return new UInt128($value);
73- //}
74-
96+ /**
97+ * @param float $value
98+ * @return Float32
99+ */
75100function float32 (float $ value ): Float32
76101{
77102 return new Float32 ($ value );
78103}
79104
105+ /**
106+ * @param float $value
107+ * @return Float64
108+ */
80109function float64 (float $ value ): Float64
81110{
82111 return new Float64 ($ value );
You can’t perform that action at this time.
0 commit comments