7
7
use Generator ;
8
8
use Ghostwriter \Option \Exception \NullPointerException ;
9
9
use Ghostwriter \Option \Exception \OptionException ;
10
+ use Ghostwriter \Option \Tests \Unit \NoneTest ;
11
+ use Ghostwriter \Option \Tests \Unit \OptionTest ;
12
+ use Ghostwriter \Option \Tests \Unit \SomeTest ;
10
13
use Throwable ;
11
14
12
15
/**
@@ -23,13 +26,12 @@ abstract class AbstractOption implements OptionInterface
23
26
/**
24
27
* @param TOption $value
25
28
*/
26
- protected function __construct (
29
+ public function __construct (
27
30
private readonly mixed $ value
28
31
) {
29
- // Singleton
30
32
}
31
33
32
- public function and (OptionInterface $ option ): OptionInterface
34
+ final public function and (OptionInterface $ option ): OptionInterface
33
35
{
34
36
if ($ this instanceof NoneInterface) {
35
37
return $ this ;
@@ -38,7 +40,7 @@ public function and(OptionInterface $option): OptionInterface
38
40
return $ option ;
39
41
}
40
42
41
- public function andThen (callable $ function ): OptionInterface
43
+ final public function andThen (callable $ function ): OptionInterface
42
44
{
43
45
if ($ this instanceof NoneInterface) {
44
46
return $ this ;
@@ -54,7 +56,7 @@ public function andThen(callable $function): OptionInterface
54
56
throw new OptionException ('Callables passed to andThen() must return an instance of OptionInterface. ' );
55
57
}
56
58
57
- public function contains (mixed $ value ): bool
59
+ final public function contains (mixed $ value ): bool
58
60
{
59
61
if ($ this instanceof NoneInterface) {
60
62
return false ;
@@ -63,7 +65,7 @@ public function contains(mixed $value): bool
63
65
return $ this ->value === $ value ;
64
66
}
65
67
66
- public function expect (Throwable $ throwable ): mixed
68
+ final public function expect (Throwable $ throwable ): mixed
67
69
{
68
70
if ($ this instanceof NoneInterface) {
69
71
throw $ throwable ;
@@ -72,7 +74,7 @@ public function expect(Throwable $throwable): mixed
72
74
return $ this ->value ;
73
75
}
74
76
75
- public function filter (callable $ function ): OptionInterface
77
+ final public function filter (callable $ function ): OptionInterface
76
78
{
77
79
return $ this ->map (
78
80
/**
@@ -87,7 +89,7 @@ public function filter(callable $function): OptionInterface
87
89
);
88
90
}
89
91
90
- public function flatten (): OptionInterface
92
+ final public function flatten (): OptionInterface
91
93
{
92
94
return $ this ->map (
93
95
/**
@@ -102,7 +104,7 @@ public function flatten(): OptionInterface
102
104
);
103
105
}
104
106
105
- public function getIterator (): Generator
107
+ final public function getIterator (): Generator
106
108
{
107
109
if ($ this instanceof NoneInterface) {
108
110
return ;
@@ -117,17 +119,17 @@ public function getIterator(): Generator
117
119
}
118
120
}
119
121
120
- public function isNone (): bool
122
+ final public function isNone (): bool
121
123
{
122
124
return $ this instanceof NoneInterface;
123
125
}
124
126
125
- public function isSome (): bool
127
+ final public function isSome (): bool
126
128
{
127
129
return $ this instanceof SomeInterface;
128
130
}
129
131
130
- public function map (callable $ function ): OptionInterface
132
+ final public function map (callable $ function ): OptionInterface
131
133
{
132
134
if ($ this instanceof NoneInterface) {
133
135
return $ this ;
@@ -136,7 +138,7 @@ public function map(callable $function): OptionInterface
136
138
return Option::create ($ function ($ this ->value ));
137
139
}
138
140
139
- public function mapOr (callable $ function , mixed $ fallback ): mixed
141
+ final public function mapOr (callable $ function , mixed $ fallback ): mixed
140
142
{
141
143
if ($ this instanceof NoneInterface) {
142
144
return $ fallback ;
@@ -145,7 +147,7 @@ public function mapOr(callable $function, mixed $fallback): mixed
145
147
return $ function ($ this ->value );
146
148
}
147
149
148
- public function mapOrElse (callable $ function , callable $ fallback ): mixed
150
+ final public function mapOrElse (callable $ function , callable $ fallback ): mixed
149
151
{
150
152
if ($ this instanceof NoneInterface) {
151
153
return $ fallback ();
@@ -154,7 +156,7 @@ public function mapOrElse(callable $function, callable $fallback): mixed
154
156
return $ function ($ this ->value );
155
157
}
156
158
157
- public function or (OptionInterface $ option ): OptionInterface
159
+ final public function or (OptionInterface $ option ): OptionInterface
158
160
{
159
161
if ($ this instanceof SomeInterface) {
160
162
return $ this ;
@@ -163,7 +165,7 @@ public function or(OptionInterface $option): OptionInterface
163
165
return $ option ;
164
166
}
165
167
166
- public function orElse (callable $ function ): OptionInterface
168
+ final public function orElse (callable $ function ): OptionInterface
167
169
{
168
170
if ($ this instanceof SomeInterface) {
169
171
return $ this ;
@@ -175,7 +177,7 @@ public function orElse(callable $function): OptionInterface
175
177
return Option::create ($ result );
176
178
}
177
179
178
- public function unwrap (): mixed
180
+ final public function unwrap (): mixed
179
181
{
180
182
if ($ this instanceof NoneInterface) {
181
183
throw new NullPointerException ();
@@ -184,7 +186,7 @@ public function unwrap(): mixed
184
186
return $ this ->value ;
185
187
}
186
188
187
- public function unwrapOr (mixed $ fallback ): mixed
189
+ final public function unwrapOr (mixed $ fallback ): mixed
188
190
{
189
191
if ($ this instanceof SomeInterface) {
190
192
return $ this ->value ;
@@ -193,7 +195,7 @@ public function unwrapOr(mixed $fallback): mixed
193
195
return $ fallback ;
194
196
}
195
197
196
- public function unwrapOrElse (callable $ function ): mixed
198
+ final public function unwrapOrElse (callable $ function ): mixed
197
199
{
198
200
if ($ this instanceof SomeInterface) {
199
201
return $ this ->value ;
0 commit comments