FirewallHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Symplify\SymfonySecurity\Tests\Adapter\Nette\DI\SymfonySecurityExtension\FirewallSource;
6
7
use Nette\Application\AbortException;
8
use Nette\Application\Application;
9
use Nette\Http\IRequest;
10
use Nette\Security\User;
11
use Symplify\SymfonySecurity\Contract\Http\FirewallHandlerInterface;
12
13
final class FirewallHandler implements FirewallHandlerInterface
14
{
15
    /**
16
     * @var User
17
     */
18
    private $user;
19
20
    public function __construct(User $user)
21
    {
22
        $this->user = $user;
23
    }
24
25
    public function getFirewallName() : string
26
    {
27
        return 'adminFirewall';
28
    }
29
30
    public function handle(Application $application, IRequest $request)
31
    {
32
        if (! $this->user->isLoggedIn()) {
33
            throw new AbortException();
34
        }
35
36
        if (! $this->user->isInRole('admin')) {
37
            throw new AbortException();
38
        }
39
    }
40
}
41