Completed
Push — master ( 3f17e5...ec676e )
by Ross
9s
created

SecurityMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
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
10
class SecurityMiddleware implements Middleware
11
{
12
    /**
13
     * @var AuthorizationCheckerInterface
14
     */
15
    private $authorizationChecker;
16
17
    /**
18
     * @param AuthorizationCheckerInterface $authorizationChecker
19
     */
20 6
    public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
21 6
        $this->authorizationChecker = $authorizationChecker;
22 6
    }
23
24
    /**
25
     * @param object $command
26
     * @param callable $next
27
     * @return mixed
28
     */
29 6
    public function execute($command, callable $next)
30
    {
31 6
        if ($this->authorizationChecker->isGranted('handle', $command)) {
32 3
            return $next($command);
33
        } else {
34 3
            throw new AccessDeniedException(
35 3
                sprintf('The current user is not allowed to handle command of type \'%s\'', get_class($command))
36 3
            );
37
        }
38
    }
39
}
40
41