SecurityMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace League\Tactician\Bundle\Middleware;
4
5
use League\Tactician\Middleware;
6
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
7
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
8
9
class SecurityMiddleware implements Middleware
10
{
11
    /**
12
     * @var AuthorizationCheckerInterface
13
     */
14
    private $authorizationChecker;
15
16
    /**
17
     * @param AuthorizationCheckerInterface $authorizationChecker
18
     */
19 18
    public function __construct(AuthorizationCheckerInterface $authorizationChecker)
20
    {
21 18
        $this->authorizationChecker = $authorizationChecker;
22 18
    }
23
24
    /**
25
     * @param object $command
26
     * @param callable $next
27
     *
28
     * @return mixed
29
     */
30 18
    public function execute($command, callable $next)
31
    {
32 18
        if ($this->authorizationChecker->isGranted('handle', $command)) {
33 9
            return $next($command);
34
        }
35
36 9
        throw new AccessDeniedException(
37 9
            sprintf('The current user is not allowed to handle command of type \'%s\'', get_class($command))
38
        );
39
    }
40
}
41
42