File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,8 @@ final public static function from(array $elements): static
91
91
#[Override]
92
92
final public static function tryFrom (array $ elements ): Result
93
93
{
94
- return static ::isValidCount ($ elements )
94
+ return static ::isValid ($ elements )
95
+ ->andThen (static fn () => static ::isValidCount ($ elements ))
95
96
->andThen (static fn () => Result \ok (static ::from ($ elements )));
96
97
}
97
98
Original file line number Diff line number Diff line change 27
27
*/
28
28
protected function __construct (protected array $ elements )
29
29
{
30
+ assert (static ::isValid ($ elements )->isOk ());
30
31
assert (static ::isValidCount ($ elements )->isOk ());
31
32
}
32
33
@@ -103,4 +104,18 @@ className: static::class,
103
104
104
105
return Result \ok (true );
105
106
}
107
+
108
+ /**
109
+ * 有効な値かどうか
110
+ * NOTE: 実装クラスでのオーバーライド用メソッド
111
+ *
112
+ * @template TIsValidKey of TKey|array-key
113
+ * @template TIsValidValue of TValue
114
+ * @param array<TIsValidKey,TIsValidValue> $elements
115
+ * @return Result<bool,ValueObjectError>
116
+ */
117
+ protected static function isValid (array $ elements ): Result
118
+ {
119
+ return Result \ok (true );
120
+ }
106
121
}
Original file line number Diff line number Diff line change @@ -147,8 +147,8 @@ final public static function from(Pair ...$values): static
147
147
#[Override]
148
148
final public static function tryFrom (Pair ...$ values ): Result
149
149
{
150
- // @phpstan-ignore-next-line
151
- return static ::isValidCount ($ values )
150
+ return static :: isValid ( $ values ) // @phpstan-ignore argument.type
151
+ -> andThen ( static fn () => static ::isValidCount ($ values )) // @phpstan-ignore argument.type
152
152
->andThen (static fn () => Result \ok (static ::from (...$ values )));
153
153
}
154
154
You can’t perform that action at this time.
0 commit comments