Skip to content

Commit be01fa2

Browse files
committed
Update AbstractOption.php
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
1 parent a2f2fe7 commit be01fa2

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/AbstractOption.php

+21-19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Generator;
88
use Ghostwriter\Option\Exception\NullPointerException;
99
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;
1013
use Throwable;
1114

1215
/**
@@ -23,13 +26,12 @@ abstract class AbstractOption implements OptionInterface
2326
/**
2427
* @param TOption $value
2528
*/
26-
protected function __construct(
29+
public function __construct(
2730
private readonly mixed $value
2831
) {
29-
// Singleton
3032
}
3133

32-
public function and(OptionInterface $option): OptionInterface
34+
final public function and(OptionInterface $option): OptionInterface
3335
{
3436
if ($this instanceof NoneInterface) {
3537
return $this;
@@ -38,7 +40,7 @@ public function and(OptionInterface $option): OptionInterface
3840
return $option;
3941
}
4042

41-
public function andThen(callable $function): OptionInterface
43+
final public function andThen(callable $function): OptionInterface
4244
{
4345
if ($this instanceof NoneInterface) {
4446
return $this;
@@ -54,7 +56,7 @@ public function andThen(callable $function): OptionInterface
5456
throw new OptionException('Callables passed to andThen() must return an instance of OptionInterface.');
5557
}
5658

57-
public function contains(mixed $value): bool
59+
final public function contains(mixed $value): bool
5860
{
5961
if ($this instanceof NoneInterface) {
6062
return false;
@@ -63,7 +65,7 @@ public function contains(mixed $value): bool
6365
return $this->value === $value;
6466
}
6567

66-
public function expect(Throwable $throwable): mixed
68+
final public function expect(Throwable $throwable): mixed
6769
{
6870
if ($this instanceof NoneInterface) {
6971
throw $throwable;
@@ -72,7 +74,7 @@ public function expect(Throwable $throwable): mixed
7274
return $this->value;
7375
}
7476

75-
public function filter(callable $function): OptionInterface
77+
final public function filter(callable $function): OptionInterface
7678
{
7779
return $this->map(
7880
/**
@@ -87,7 +89,7 @@ public function filter(callable $function): OptionInterface
8789
);
8890
}
8991

90-
public function flatten(): OptionInterface
92+
final public function flatten(): OptionInterface
9193
{
9294
return $this->map(
9395
/**
@@ -102,7 +104,7 @@ public function flatten(): OptionInterface
102104
);
103105
}
104106

105-
public function getIterator(): Generator
107+
final public function getIterator(): Generator
106108
{
107109
if ($this instanceof NoneInterface) {
108110
return;
@@ -117,17 +119,17 @@ public function getIterator(): Generator
117119
}
118120
}
119121

120-
public function isNone(): bool
122+
final public function isNone(): bool
121123
{
122124
return $this instanceof NoneInterface;
123125
}
124126

125-
public function isSome(): bool
127+
final public function isSome(): bool
126128
{
127129
return $this instanceof SomeInterface;
128130
}
129131

130-
public function map(callable $function): OptionInterface
132+
final public function map(callable $function): OptionInterface
131133
{
132134
if ($this instanceof NoneInterface) {
133135
return $this;
@@ -136,7 +138,7 @@ public function map(callable $function): OptionInterface
136138
return Option::create($function($this->value));
137139
}
138140

139-
public function mapOr(callable $function, mixed $fallback): mixed
141+
final public function mapOr(callable $function, mixed $fallback): mixed
140142
{
141143
if ($this instanceof NoneInterface) {
142144
return $fallback;
@@ -145,7 +147,7 @@ public function mapOr(callable $function, mixed $fallback): mixed
145147
return $function($this->value);
146148
}
147149

148-
public function mapOrElse(callable $function, callable $fallback): mixed
150+
final public function mapOrElse(callable $function, callable $fallback): mixed
149151
{
150152
if ($this instanceof NoneInterface) {
151153
return $fallback();
@@ -154,7 +156,7 @@ public function mapOrElse(callable $function, callable $fallback): mixed
154156
return $function($this->value);
155157
}
156158

157-
public function or(OptionInterface $option): OptionInterface
159+
final public function or(OptionInterface $option): OptionInterface
158160
{
159161
if ($this instanceof SomeInterface) {
160162
return $this;
@@ -163,7 +165,7 @@ public function or(OptionInterface $option): OptionInterface
163165
return $option;
164166
}
165167

166-
public function orElse(callable $function): OptionInterface
168+
final public function orElse(callable $function): OptionInterface
167169
{
168170
if ($this instanceof SomeInterface) {
169171
return $this;
@@ -175,7 +177,7 @@ public function orElse(callable $function): OptionInterface
175177
return Option::create($result);
176178
}
177179

178-
public function unwrap(): mixed
180+
final public function unwrap(): mixed
179181
{
180182
if ($this instanceof NoneInterface) {
181183
throw new NullPointerException();
@@ -184,7 +186,7 @@ public function unwrap(): mixed
184186
return $this->value;
185187
}
186188

187-
public function unwrapOr(mixed $fallback): mixed
189+
final public function unwrapOr(mixed $fallback): mixed
188190
{
189191
if ($this instanceof SomeInterface) {
190192
return $this->value;
@@ -193,7 +195,7 @@ public function unwrapOr(mixed $fallback): mixed
193195
return $fallback;
194196
}
195197

196-
public function unwrapOrElse(callable $function): mixed
198+
final public function unwrapOrElse(callable $function): mixed
197199
{
198200
if ($this instanceof SomeInterface) {
199201
return $this->value;

0 commit comments

Comments
 (0)