Passed
Push — master ( 5e0f86...fc8c86 )
by Tim
02:36
created

AbstractHandler::getSiteFromRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LD\LanguageDetection\Handler;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
10
11
abstract class AbstractHandler
12
{
13
    protected EventDispatcherInterface $eventDispatcher;
14
15
    public function __construct(EventDispatcherInterface $eventDispatcher)
16
    {
17
        $this->eventDispatcher = $eventDispatcher;
18
    }
19
20
    protected function getSiteFromRequest(ServerRequestInterface $request): SiteInterface
21
    {
22
        $site = $request->getAttribute('site');
23
        if (!($site instanceof SiteInterface)) {
24
            throw new \Exception('Found no valid site object in request', 1_637_813_123);
0 ignored issues
show
Bug introduced by
The constant LD\LanguageDetection\Handler\1_637_813_123 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
25
        }
26
27
        return $site;
28
    }
29
}
30