Test Setup Failed
Pull Request — master (#4522)
by Craig
08:26 queued 03:47
created

AdminRuntime   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A adminUpdateCheck() 0 5 1
A adminHeader() 0 5 1
A adminPanelMenu() 0 3 1
A adminBreadcrumbs() 0 5 1
A adminFooter() 0 5 1
A adminSecurityAnalyzer() 0 5 1
A adminMenu() 0 12 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\AdminModule\Twig\Runtime;
15
16
use Symfony\Component\HttpKernel\Controller\ControllerReference;
17
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
18
use Twig\Extension\RuntimeExtensionInterface;
19
use Zikula\PermissionsModule\Api\ApiInterface\PermissionApiInterface;
20
21
class AdminRuntime implements RuntimeExtensionInterface
22
{
23
    /**
24
     * @var FragmentHandler
25
     */
26
    private $handler;
27
28
    /**
29
     * @var PermissionApiInterface
30
     */
31
    private $permissionApi;
32
33
    public function __construct(FragmentHandler $handler, PermissionApiInterface $permissionApi)
34
    {
35
        $this->handler = $handler;
36
        $this->permissionApi = $permissionApi;
37
    }
38
39
    public function adminBreadcrumbs(): string
40
    {
41
        $ref = new ControllerReference('Zikula\AdminModule\Controller\AdminInterfaceController::breadcrumbs');
42
43
        return $this->handler->render($ref) ?? '';
44
    }
45
46
    public function adminFooter(): string
47
    {
48
        $ref = new ControllerReference('Zikula\AdminModule\Controller\AdminInterfaceController::footer');
49
50
        return $this->handler->render($ref) ?? '';
51
    }
52
53
    public function adminHeader(): string
54
    {
55
        $ref = new ControllerReference('Zikula\AdminModule\Controller\AdminInterfaceController::header');
56
57
        return $this->handler->render($ref) ?? '';
58
    }
59
60
    public function adminMenu(string $mode = 'categories', string $template = 'tabs'): string
61
    {
62
        if (!$this->permissionApi->hasPermission('ZikulaAdminModule::', '::', ACCESS_EDIT)) {
63
            return ''; // Since no permission, return empty
64
        }
65
66
        $ref = new ControllerReference('Zikula\AdminModule\Controller\AdminInterfaceController::menu', [
67
            'mode' => $mode,
68
            'template' => $template
69
        ]);
70
71
        return $this->handler->render($ref) ?? '';
72
    }
73
74
    public function adminPanelMenu(string $mode = 'modules', string $template = 'panel'): string
75
    {
76
        return $this->adminMenu($mode, $template);
77
    }
78
79
    public function adminSecurityAnalyzer(): string
80
    {
81
        $ref = new ControllerReference('Zikula\AdminModule\Controller\AdminInterfaceController::securityanalyzer');
82
83
        return $this->handler->render($ref) ?? '';
84
    }
85
86
    public function adminUpdateCheck(): string
87
    {
88
        $ref = new ControllerReference('Zikula\AdminModule\Controller\AdminInterfaceController::updatecheck');
89
90
        return $this->handler->render($ref) ?? '';
91
    }
92
}
93