Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Notification | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFunctions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| notifications | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Engelsystem\Renderer\Twig\Extensions; |
| 6 | |
| 7 | use Engelsystem\Controllers\HasUserNotifications; |
| 8 | use Engelsystem\Controllers\NotificationType; |
| 9 | use Illuminate\Support\Collection; |
| 10 | use Symfony\Component\HttpFoundation\Session\Session as SymfonySession; |
| 11 | use Twig\Extension\AbstractExtension as TwigExtension; |
| 12 | use Twig\TwigFunction; |
| 13 | |
| 14 | class Notification extends TwigExtension |
| 15 | { |
| 16 | use HasUserNotifications; |
| 17 | |
| 18 | public function __construct(protected SymfonySession $session) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @return TwigFunction[] |
| 24 | */ |
| 25 | public function getFunctions(): array |
| 26 | { |
| 27 | return [ |
| 28 | new TwigFunction('notifications', [$this, 'notifications']), |
| 29 | ]; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @return Collection|Collection[] |
| 34 | */ |
| 35 | public function notifications(?string $type = null): Collection |
| 36 | { |
| 37 | $types = $type ? [NotificationType::from($type)] : null; |
| 38 | |
| 39 | $messages = $this->getNotifications($types); |
| 40 | if ($types) { |
| 41 | $messages = $messages[$type] ?? []; |
| 42 | } |
| 43 | |
| 44 | return collect($messages); |
| 45 | } |
| 46 | } |