BackendUserCheck   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A __invoke() 0 10 3
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