AccessDeniedListener   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A onPostRespond() 0 11 4
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Security\EventListener;
15
16
use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
17
use Silverback\ApiComponentsBundle\EventListener\Api\ApiEventListenerTrait;
18
use Silverback\ApiComponentsBundle\Mercure\MercureAuthorization;
19
use Symfony\Component\HttpKernel\Event\ResponseEvent;
20
21
class AccessDeniedListener
22
{
23
    use ApiEventListenerTrait;
0 ignored issues
show
Bug introduced by
The trait Silverback\ApiComponents...i\ApiEventListenerTrait requires the property $attributes which is not provided by Silverback\ApiComponents...er\AccessDeniedListener.
Loading history...
24
25
    public function __construct(
26
        private readonly MercureAuthorization $mercureAuthorization
27
    ) {
28
    }
29
30
    public function onPostRespond(ResponseEvent $event): void
31
    {
32
        $request = $event->getRequest();
33
        $attributes = $this->getAttributes($request);
34
        if (
35
            !($operation = $attributes['operation'] ?? null)
36
            || 'me' !== $operation->getName()
37
            || !($response = $event->getResponse()) instanceof JWTAuthenticationFailureResponse) {
38
            return;
39
        }
40
        $response->headers->setCookie($this->mercureAuthorization->getClearAuthorizationCookie());
41
    }
42
}
43