Add PHPStan

This commit is contained in:
Oliver Davies 2025-05-04 21:45:20 +01:00
parent 419d1cec14
commit 9abfb29af7
7 changed files with 203 additions and 19 deletions

View file

@ -9,9 +9,15 @@ use Countable;
use Iterator;
use IteratorAggregate;
abstract class AbstractCollection implements Countable, IteratorAggregate
/**
* @template TItem
*/
class Collection implements Countable, IteratorAggregate
{
public function __construct(protected array $items = [])
/**
* @param TItem[] $items
*/
final public function __construct(protected array $items = [])
{
}
@ -35,6 +41,9 @@ abstract class AbstractCollection implements Countable, IteratorAggregate
return new ArrayIterator($this->items);
}
/**
* @return TItem[]
*/
public function toArray(): array
{
return $this->items;

View file

@ -1,9 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Presentation\Collection;
final class EventCollection extends AbstractCollection
{
}

View file

@ -7,9 +7,9 @@ namespace App\Presentation\Collection;
use DateTimeImmutable;
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
final class PresentationCollection extends AbstractCollection
final class PresentationCollection extends Collection
{
public function getAllEvents(): EventCollection
public function getAllEvents(): Collection
{
$events = array_reduce(
array: $this->items,
@ -21,10 +21,10 @@ final class PresentationCollection extends AbstractCollection
initial: [],
);
return new EventCollection(array_merge(...$events));
return new Collection(array_merge(...$events));
}
public function getPastEvents(): EventCollection
public function getPastEvents(): Collection
{
$today = new DateTimeImmutable('today');