DenyAllMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 1
A __construct() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace jschreuder\MiddleAuth\Basic;
4
5
use jschreuder\MiddleAuth\AuthorizationHandlerInterface;
6
use jschreuder\MiddleAuth\AuthorizationMiddlewareInterface;
7
use jschreuder\MiddleAuth\AuthorizationRequestInterface;
8
use jschreuder\MiddleAuth\AuthorizationResponseInterface;
9
use jschreuder\MiddleAuth\Util\AuthLoggerInterface;
10
use jschreuder\MiddleAuth\Util\NullAuthLogger;
11
12
final class DenyAllMiddleware implements AuthorizationMiddlewareInterface
13
{
14
    private AuthLoggerInterface $logger;
15
16 3
    public function __construct(
17
        ?AuthLoggerInterface $logger = null
18
    )
19
    {
20 3
        $this->logger = $logger ?? new NullAuthLogger();
21
    }
22
23 2
    public function process(
24
        AuthorizationRequestInterface $request,
25
        AuthorizationHandlerInterface $handler
26
    ): AuthorizationResponseInterface
27
    {
28 2
        $this->logger->info('DenyAllMiddleware rejecting request - no authorization rules matched', [
29 2
            'subject_type' => $request->getSubject()->getType(),
30 2
            'subject_id' => $request->getSubject()->getId(),
31 2
            'resource_type' => $request->getResource()?->getType(),
32 2
            'resource_id' => $request->getResource()?->getId(),
33 2
            'action' => $request->getAction(),
34 2
        ]);
35
36 2
        return new AuthorizationResponse(false, 'No authorization rule matched', self::class);
37
    }
38
}
39