FallbackDashboardDetector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRoute() 0 3 1
A isAdminArea() 0 5 1
A getDashboardControllerFqcn() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ThemeBundle\Helper;
15
16
use Symfony\Component\HttpFoundation\Request;
17
use Zikula\ThemeBundle\Controller\Dashboard\AdminDashboardController;
18
use Zikula\ThemeBundle\Controller\Dashboard\UserDashboardController;
19
20
/**
21
 * Helper for dynamic default dashboard selection, used by CreateThemedResponseSubscriber and non-EAB controllers.
22
 */
23
class FallbackDashboardDetector
24
{
25
    private const ROUTE_PART_ADMIN = '_admin_';
26
27
    public function isAdminArea(Request $request): bool
28
    {
29
        $route = $this->getRoute($request);
30
31
        return str_contains($route, self::ROUTE_PART_ADMIN);
32
    }
33
34
    public function getDashboardControllerFqcn(Request $request): string
35
    {
36
        $isAdminArea = $this->isAdminArea($request);
37
        $request->attributes->set('isAdminArea', $isAdminArea);
38
39
        return $isAdminArea ? AdminDashboardController::class : UserDashboardController::class;
40
    }
41
42
    private function getRoute(Request $request): string
43
    {
44
        return $request->attributes->get('_route') ?? '';
45
    }
46
}
47