Skip to content

Commit 7174bb5

Browse files
fix: Resolve type inconsistencies in filter methods
- Fix sole() method to use filterStrict() for static return type consistency - Fix reject() method to use filterStrict() since it returns static - Fix ValueObjectList remove() and diff() methods to use filterStrict() - Ensures type safety between filter() (returns self) and filterStrict() (returns static) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: kakiuchi-shigenao <endou-mame@users.noreply.github.com>
1 parent 4cded0d commit 7174bb5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Collection/ArrayList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ final public function firstOrFail(?Closure $closure = null)
253253
#[Override]
254254
final public function sole(?Closure $closure = null)
255255
{
256-
$items = $closure === null ? new static($this->elements) : $this->filter($closure);
256+
$items = $closure === null ? new static($this->elements) : $this->filterStrict($closure);
257257
$count = $items->count();
258258

259259
if ($count === 0) {
@@ -352,7 +352,7 @@ final public function filterStrict(Closure $closure): static
352352
#[Override]
353353
final public function reject(Closure $closure): static
354354
{
355-
return $this->filter(static fn ($value, $key) => !$closure($value, $key));
355+
return $this->filterStrict(static fn ($value, $key) => !$closure($value, $key));
356356
}
357357

358358
#[Override]

src/ValueObjectList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function has(IValueObject $element): bool
2727
*/
2828
public function remove(IValueObject $element): static
2929
{
30-
return $this->filter(static fn (IValueObject $e) => !$e->equals($element));
30+
return $this->filterStrict(static fn (IValueObject $e) => !$e->equals($element));
3131
}
3232

3333
/**
@@ -45,6 +45,6 @@ public function put(IValueObject $element): static
4545
*/
4646
public function diff(self $other): static
4747
{
48-
return $this->filter(static fn (IValueObject $e) => !$other->has($e));
48+
return $this->filterStrict(static fn (IValueObject $e) => !$other->has($e));
4949
}
5050
}

0 commit comments

Comments
 (0)