chore: Increase PHPStan to level 6 [ci skip]

This commit is contained in:
Oliver Davies 2021-09-12 20:17:28 +01:00
parent e15b317d09
commit b924e51103
3 changed files with 26 additions and 1 deletions

View file

@ -1,4 +1,4 @@
parameters:
level: 5
level: 6
paths:
- src

View file

@ -7,17 +7,27 @@ namespace App\Collection;
use Carbon\Carbon;
use Illuminate\Support\Collection;
/**
* @template TKey of array-key
* @template TValue
*/
final class TalkCollection extends Collection
{
private const DATE_FORMAT = 'Y-m-d';
private const KEY_EVENTS = 'events';
private const KEY_EVENT_DATE = 'date';
/**
* @return self<TKey, TValue>
*/
public function getEvents(): self
{
return $this->flatMap(fn($talk): array => (array) $talk[self::KEY_EVENTS]);
}
/**
* @return self<TKey, TValue>
*/
public function onlyPastTalks(): self
{
$today = Carbon::today()->format(self::DATE_FORMAT);

View file

@ -9,6 +9,10 @@ use Illuminate\Support\Collection;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* @template TKey of array-key
* @template TValue
*/
final class TalkExtension extends AbstractExtension
{
public function getFunctions()
@ -19,6 +23,9 @@ final class TalkExtension extends AbstractExtension
];
}
/**
* @param TValue $talk
*/
public function getLastEventDate($talk): ?string
{
$events = new Collection($talk['events']);
@ -26,11 +33,19 @@ final class TalkExtension extends AbstractExtension
return $events->pluck('date')->sort()->last();
}
/**
* @param iterable<int, TValue> $talks
*/
public function getPastTalkCount(iterable $talks = []): int
{
return $this->getEventsFromTalks($talks)->count();
}
/**
* @param iterable<int, TValue> $talks
*
* @return TalkCollection<int, TValue>
*/
private function getEventsFromTalks(iterable $talks): TalkCollection
{
$talkCollection = new TalkCollection($talks);