Skip to content

Commit eb5780b

Browse files
authored
Merge branch 'master' into dev
2 parents 1f3ad86 + 2b8bf98 commit eb5780b

File tree

4 files changed

+104
-23
lines changed

4 files changed

+104
-23
lines changed

src/Composite/Dictionary.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
class Dictionary
99
{
10-
private array $elements;
10+
/**
11+
* @var array
12+
*/
13+
private array $elements = [];
1114

1215
public function __construct(array $elements = [])
1316
{
@@ -21,13 +24,22 @@ public function __construct(array $elements = [])
2124
$this->elements = $elements;
2225
}
2326

24-
// Add a key-value pair to the dictionary
27+
28+
/**
29+
* @param string $key
30+
* @param $value
31+
* @return void
32+
*/
2533
public function add(string $key, $value): void
2634
{
2735
$this->elements[$key] = $value;
2836
}
2937

30-
// Get the value associated with a key
38+
39+
/**
40+
* @param string $key
41+
* @return mixed
42+
*/
3143
public function get(string $key)
3244
{
3345
if (!isset($this->elements[$key])) {
@@ -37,7 +49,11 @@ public function get(string $key)
3749
return $this->elements[$key];
3850
}
3951

40-
// Remove a key-value pair by the key
52+
53+
/**
54+
* @param string $key
55+
* @return void
56+
*/
4157
public function remove(string $key): void
4258
{
4359
if (!isset($this->elements[$key])) {
@@ -47,31 +63,45 @@ public function remove(string $key): void
4763
unset($this->elements[$key]);
4864
}
4965

50-
// Check if a key exists in the dictionary
66+
/**
67+
* @param string $key
68+
* @return bool
69+
*/
5170
public function containsKey(string $key): bool
5271
{
5372
return array_key_exists($key, $this->elements);
5473
}
5574

56-
// Get all keys in the dictionary
75+
76+
/**
77+
* @return array
78+
*/
5779
public function getKeys(): array
5880
{
5981
return array_keys($this->elements);
6082
}
6183

62-
// Get all values in the dictionary
84+
85+
/**
86+
* @return array
87+
*/
6388
public function getValues(): array
6489
{
6590
return array_values($this->elements);
6691
}
6792

68-
// Get the size of the dictionary
93+
/**
94+
* @return int
95+
*/
6996
public function size(): int
7097
{
7198
return count($this->elements);
7299
}
73100

74-
// Clear the dictionary
101+
102+
/**
103+
* @return void
104+
*/
75105
public function clear(): void
76106
{
77107
$this->elements = [];

src/Composite/Struct/Struct.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
final 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
{

src/Composite/Union/Union.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,46 @@
66

77
final 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);

src/helpers.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,91 @@
2121
use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt32;
2222
use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt8;
2323

24+
/**
25+
* @param int $value
26+
* @return Int8
27+
*/
2428
function int8(int $value): Int8
2529
{
2630
return new Int8($value);
2731
}
2832

33+
/**
34+
* @param int $value
35+
* @return Int16
36+
*/
2937
function int16(int $value): Int16
3038
{
3139
return new Int16($value);
3240
}
3341

42+
/**
43+
* @param int $value
44+
* @return Int32
45+
*/
3446
function int32(int $value): Int32
3547
{
3648
return new Int32($value);
3749
}
3850

51+
/**
52+
* @param int $value
53+
* @return Int64
54+
*/
3955
function int64(int $value): Int64
4056
{
4157
return new Int64($value);
4258
}
4359

60+
/**
61+
* @param int $value
62+
* @return Int128
63+
*/
4464
function int128(int $value): Int128
4565
{
4666
return new Int128($value);
4767
}
4868

69+
/**
70+
* @param int $value
71+
* @return UInt8
72+
*/
4973
function uint8(int $value): UInt8
5074
{
5175
return new UInt8($value);
5276
}
5377

78+
/**
79+
* @param int $value
80+
* @return UInt16
81+
*/
5482
function uint16(int $value): UInt16
5583
{
5684
return new UInt16($value);
5785
}
5886

87+
/**
88+
* @param int $value
89+
* @return UInt32
90+
*/
5991
function 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+
*/
75100
function float32(float $value): Float32
76101
{
77102
return new Float32($value);
78103
}
79104

105+
/**
106+
* @param float $value
107+
* @return Float64
108+
*/
80109
function float64(float $value): Float64
81110
{
82111
return new Float64($value);

0 commit comments

Comments
 (0)