Passed
Pull Request — master (#1703)
by Tarmo
08:51
created

DoctrineExtensionSubscriber::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/EventSubscriber/DoctrineExtensionSubscriber.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\EventSubscriber;
10
11
use App\Security\UserTypeIdentification;
12
use Doctrine\ORM\NonUniqueResultException;
13
use Gedmo\Blameable\BlameableListener;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
use Symfony\Component\HttpKernel\Event\RequestEvent;
16
17
/**
18
 * Class DoctrineExtensionSubscriber
19
 *
20
 * @package App\EventSubscriber
21
 * @author TLe, Tarmo Leppänen <[email protected]>
22
 */
23
class DoctrineExtensionSubscriber implements EventSubscriberInterface
24
{
25 336
    public function __construct(
26
        private BlameableListener $blameableListener,
27
        private UserTypeIdentification $userTypeIdentification,
28
    ) {
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     *
34
     * @return array<string, string>
35
     */
36 2
    public static function getSubscribedEvents(): array
37
    {
38
        return [
39 2
            RequestEvent::class => 'onKernelRequest',
40
        ];
41
    }
42
43
    /**
44
     * @throws NonUniqueResultException
45
     */
46 332
    public function onKernelRequest(): void
47
    {
48 332
        $user = $this->userTypeIdentification->getUser();
49
50 332
        if ($user !== null) {
51 254
            $this->blameableListener->setUserValue($user);
52
        }
53
    }
54
}
55