Add PHPStan
This commit is contained in:
parent
419d1cec14
commit
9abfb29af7
7 changed files with 203 additions and 19 deletions
51
src/Presentation/Collection/Collection.php
Normal file
51
src/Presentation/Collection/Collection.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presentation\Collection;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Iterator;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* @template TItem
|
||||
*/
|
||||
class Collection implements Countable, IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @param TItem[] $items
|
||||
*/
|
||||
final public function __construct(protected array $items = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
|
||||
public function filter(callable $callback): self
|
||||
{
|
||||
return new static(
|
||||
array_filter(
|
||||
array: $this->items,
|
||||
callback: $callback,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getIterator(): Iterator
|
||||
{
|
||||
return new ArrayIterator($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TItem[]
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue