CurrentSiteListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FH\Bundle\MultiSiteBundle\Request;
6
7
use FH\Bundle\MultiSiteBundle\Site\SiteResolverInterface;
8
use Symfony\Component\HttpKernel\Event\RequestEvent;
9
use Symfony\Component\HttpKernel\HttpKernelInterface;
10
use Symfony\Component\Routing\RequestContext;
11
12
/**
13
 * @author Joris van de Sande <[email protected]>
14
 */
15
final class CurrentSiteListener
16
{
17
    private $siteResolver;
18
19
    public function __construct(SiteResolverInterface $siteResolver)
20
    {
21
        $this->siteResolver = $siteResolver;
22
    }
23
24
    public function __invoke(RequestEvent $event): void
25
    {
26
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
0 ignored issues
show
Deprecated Code introduced by
The constant Symfony\Component\HttpKe...terface::MASTER_REQUEST has been deprecated: since symfony/http-kernel 5.3, use MAIN_REQUEST instead. To ease the migration, this constant won't be removed until Symfony 7.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

26
        if (/** @scrutinizer ignore-deprecated */ HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
27
            return;
28
        }
29
30
        $request = $event->getRequest();
31
        $requestContext = new RequestContext();
32
        $requestContext->fromRequest($request);
33
34
        $site = $this->siteResolver->resolve($requestContext);
35
36
        $request->attributes->set('site', $site);
37
    }
38
}
39