BackendUserCheck::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Check;
6
7
use Lochmueller\LanguageDetection\Event\CheckLanguageDetectionEvent;
8
use Lochmueller\LanguageDetection\Service\SiteConfigurationService;
9
use TYPO3\CMS\Core\Context\Context;
10
use TYPO3\CMS\Core\Utility\GeneralUtility;
11
12
class BackendUserCheck
13
{
14
    public function __construct(protected SiteConfigurationService $siteConfigurationService) {}
15
16
    public function __invoke(CheckLanguageDetectionEvent $event): void
17
    {
18
        if (!$this->siteConfigurationService->getConfiguration($event->getSite())->isDisableRedirectWithBackendSession()) {
19
            return;
20
        }
21
        /** @var Context $context */
22
        $context = GeneralUtility::makeInstance(Context::class);
23
        $isLoggedIn = (bool)$context->getAspect('backend.user')->get('isLoggedIn');
24
        if ($isLoggedIn) {
25
            $event->disableLanguageDetection();
26
        }
27
    }
28
}
29