Skip to content

Commit 4430ac8

Browse files
authored
Merge pull request #52 from wiz-develop:endou-mame/issue50
fix: PHPDocの型注釈を修正し、不要なテストを削除
2 parents 6443d2c + dd0fa19 commit 4430ac8

File tree

4 files changed

+31
-49
lines changed

4 files changed

+31
-49
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
timeoutForSmallTests="1"
1212
timeoutForMediumTests="10"
1313
timeoutForLargeTests="60"
14+
displayDetailsOnTestsThatTriggerWarnings="true"
1415
>
1516
<testsuites>
1617
<testsuite name="Unit">

src/Option/functions.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ function none(): Option\None
3636
* It will be a `Some` option containing `$value` if `$value` is different from `$noneValue` (default `null`)
3737
*
3838
* @template U
39-
* @param U|null $value
40-
* @return Option<U>
39+
* @template NoneValue
40+
*
41+
* @param U $value
42+
* @param NoneValue|null $noneValue
43+
*
44+
* @return ($noneValue is null ? Option<U> : Option<U|NoneValue>)
4145
*/
42-
function fromValue($value, mixed $noneValue = null, bool $strict = true): Option
46+
function fromValue($value, mixed $noneValue = null): Option
4347
{
44-
$same = $strict
45-
? ($value === $noneValue)
46-
: ($value == $noneValue);
47-
48-
return $same
48+
return $value === $noneValue
4949
? Option\none()
5050
: Option\some($value);
5151
}
@@ -55,33 +55,41 @@ function fromValue($value, mixed $noneValue = null, bool $strict = true): Option
5555
* It will be a `Some` option containing the result if it is different from `$noneValue` (default `null`).
5656
*
5757
* @template U
58-
* @param callable():U|null $callback
59-
* @return Option<U>
58+
* @template NoneValue
59+
*
60+
* @param callable():U $callback
61+
* @param NoneValue|null $noneValue
62+
*
63+
* @return ($noneValue is null ? Option<U> : Option<U|NoneValue>)
6064
*/
61-
function of(callable $callback, mixed $noneValue = null, bool $strict = true): Option
65+
function of(callable $callback, mixed $noneValue = null): Option
6266
{
63-
return Option\fromValue($callback(), $noneValue, $strict);
67+
return Option\fromValue($callback(), $noneValue);
6468
}
6569

6670
/**
6771
* Execute a callable and transform the result into an `Option` as `Option\of()` does
6872
* but also return `Option\None` if it an exception matching $exceptionClass was thrown.
6973
*
7074
* @template U
75+
* @template NoneValue
7176
* @template E of \Throwable
72-
* @param callable():U|null $callback
73-
* @param class-string<E> $exceptionClass
74-
* @return Option<U>
77+
*
78+
* @param callable():U $callback
79+
* @param NoneValue|null $noneValue
80+
* @param class-string<E> $exceptionClass
81+
*
82+
* @return ($noneValue is null ? Option<U> : Option<U|NoneValue>)
83+
*
7584
* @throws Throwable
7685
*/
7786
function tryOf(
7887
callable $callback,
7988
mixed $noneValue = null,
80-
bool $strict = true,
8189
string $exceptionClass = Exception::class,
8290
): Option {
8391
try {
84-
return Option\of($callback, $noneValue, $strict);
92+
return Option\of($callback, $noneValue);
8593
} catch (Throwable $th) {
8694
if (is_a($th, $exceptionClass)) {
8795
return Option\none();
@@ -95,7 +103,8 @@ function tryOf(
95103
* Converts from `Option<Option<T>>` to `Option<T>`.
96104
*
97105
* @template U
98-
* @param Option<Option<U>> $option
106+
* @param Option<Option<U>> $option
107+
*
99108
* @return Option<U>
100109
*/
101110
function flatten(Option $option): Option
@@ -113,7 +122,9 @@ function flatten(Option $option): Option
113122
*
114123
* @template U
115124
* @template E
116-
* @param Option<Result<U, E>> $option
125+
*
126+
* @param Option<Result<U, E>> $option
127+
*
117128
* @return Result<Option<U>, E>
118129
*/
119130
function transpose(Option $option): Result

tests/Unit/Option/OfTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,6 @@ public function tryOfDefaultToNull(): void
5959
Assert::assertEquals(Option\some(1), Option\tryOf(static fn () => 1));
6060
}
6161

62-
#[Test]
63-
#[TestDox('ofDefaultToStrict test')]
64-
public function ofDefaultToStrict(): void
65-
{
66-
$o = (object)[];
67-
68-
Assert::assertEquals(Option\none(), Option\of(static fn () => $o, (object)[], strict: false));
69-
Assert::assertEquals($o, Option\of(static fn () => $o, (object)[])->unwrap());
70-
}
71-
72-
#[Test]
73-
#[TestDox('tryOfDefaultToStrict test')]
74-
public function tryOfDefaultToStrict(): void
75-
{
76-
$o = (object)[];
77-
78-
Assert::assertEquals(Option\none(), Option\tryOf(static fn () => $o, (object)[], strict: false));
79-
Assert::assertEquals($o, Option\tryOf(static fn () => $o, (object)[])->unwrap());
80-
}
81-
8262
#[Test]
8363
#[TestDox('tryOfExeptions test')]
8464
public function tryOfExeptions(): void

tests/Unit/Result/CombineTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,4 @@ public function combineWithErrors(): void
5454
Assert::assertTrue($errors[0] === 'error1');
5555
Assert::assertTrue($errors[1] === 'error2');
5656
}
57-
58-
#[Test]
59-
#[TestDox('空の配列を渡した場合はOk(true)を返すcombineのテスト')]
60-
public function combineEmpty(): void
61-
{
62-
$result = Result\combine();
63-
64-
Assert::assertTrue($result->isOk());
65-
Assert::assertTrue($result->unwrap());
66-
}
6757
}

0 commit comments

Comments
 (0)