Skip to content

Commit 2523867

Browse files
authoredMay 8, 2025··
Merge pull request #16 from wiz-develop/endou-mame/issue15
·
v0.6.4v0.5.2
2 parents 2eb24c6 + 7757948 commit 2523867

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed
 

‎src/Collection/ArrayList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ final public static function from(array $elements): static
9191
#[Override]
9292
final public static function tryFrom(array $elements): Result
9393
{
94-
return static::isValidCount($elements)
94+
return static::isValid($elements)
95+
->andThen(static fn () => static::isValidCount($elements))
9596
->andThen(static fn () => Result\ok(static::from($elements)));
9697
}
9798

‎src/Collection/Base/CollectionBase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
protected function __construct(protected array $elements)
2929
{
30+
assert(static::isValid($elements)->isOk());
3031
assert(static::isValidCount($elements)->isOk());
3132
}
3233

@@ -103,4 +104,18 @@ className: static::class,
103104

104105
return Result\ok(true);
105106
}
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+
}
106121
}

‎src/Collection/Map.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ final public static function from(Pair ...$values): static
147147
#[Override]
148148
final public static function tryFrom(Pair ...$values): Result
149149
{
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
152152
->andThen(static fn () => Result\ok(static::from(...$values)));
153153
}
154154

0 commit comments

Comments
 (0)
Please sign in to comment.