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: parameters:
level: 5 level: 6
paths: paths:
- src - src

View file

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

View file

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