Skip to content

Commit

Permalink
add matching() as safe method
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Oct 8, 2023
1 parent ed10520 commit 3e21663
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Fix nullable intersection type problem with PHP 8.1
* Only keep `ExtraLazyCollection`
* Fix all `matching()` signature to return `ReadableCollection&Selectable`
* Add `matching()` as safe method to `ExtraLazyCollection`

## 2.1.1

Expand Down
30 changes: 24 additions & 6 deletions src/ExtraLazy/ExtraLazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,42 @@
namespace Rekalogika\Collections\Decorator\ExtraLazy;

use Doctrine\Common\Collections\Collection;
use Rekalogika\Collections\Decorator\AbstractRejectDecorator\AbstractCollectionRejectDecorator;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\Common\Collections\Selectable;
use Rekalogika\Collections\Decorator\AbstractRejectDecorator\AbstractSelectableCollectionRejectDecorator;
use Rekalogika\Collections\Decorator\Trait\CountableDecoratorTrait;

/**
* @template TKey of array-key
* @template T
* @extends AbstractCollectionRejectDecorator<TKey,T>
* @extends AbstractSelectableCollectionRejectDecorator<TKey,T>
*/
class ExtraLazyCollection extends AbstractCollectionRejectDecorator
class ExtraLazyCollection extends AbstractSelectableCollectionRejectDecorator
{
use CountableDecoratorTrait;

/**
* @var Collection<TKey,T>&Selectable<TKey,T>
*/
private Collection $wrapped;

/**
* @param Collection<TKey,T> $wrapped
*/
public function __construct(private Collection $wrapped)
public function __construct(Collection $wrapped)
{
if (!$wrapped instanceof Selectable) {
throw new \InvalidArgumentException('The wrapped collection must implement Selectable');
}

$this->wrapped = $wrapped;
}

/**
* @return Collection<TKey,T>
* @return Collection<TKey,T>&Selectable<TKey,T>
*/
protected function getWrapped(): Collection
protected function getWrapped(): Collection&Selectable
{
return $this->wrapped;
}
Expand Down Expand Up @@ -96,4 +109,9 @@ public function add(mixed $element): void
{
$this->getWrapped()->add($element);
}

public function matching(Criteria $criteria): ReadableCollection&Selectable
{
return $this->getWrapped()->matching($criteria);
}
}

0 comments on commit 3e21663

Please sign in to comment.