Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Authentication
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFunctions
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 isAuthenticated
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isGuest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Renderer\Twig\Extensions;
6
7use Engelsystem\Helpers\Authenticator;
8use Twig\Extension\AbstractExtension as TwigExtension;
9use Twig\TwigFunction;
10
11class Authentication extends TwigExtension
12{
13    public function __construct(protected Authenticator $auth)
14    {
15    }
16
17    /**
18     * @return TwigFunction[]
19     */
20    public function getFunctions(): array
21    {
22        return [
23            new TwigFunction('is_user', [$this, 'isAuthenticated']),
24            new TwigFunction('is_guest', [$this, 'isGuest']),
25            new TwigFunction('can', [$this->auth, 'can']),
26            new TwigFunction('canAny', [$this->auth, 'canAny']),
27        ];
28    }
29
30    public function isAuthenticated(): bool
31    {
32        return (bool) $this->auth->user();
33    }
34
35    public function isGuest(): bool
36    {
37        return !$this->isAuthenticated();
38    }
39}