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

PermissionsRuntime   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPermission() 0 7 4
A __construct() 0 4 1
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\PermissionsModule\Twig\Runtime;
15
16
use InvalidArgumentException;
17
use Symfony\Contracts\Translation\TranslatorInterface;
18
use Twig\Extension\RuntimeExtensionInterface;
19
use Zikula\PermissionsModule\Api\ApiInterface\PermissionApiInterface;
20
21
class PermissionsRuntime implements RuntimeExtensionInterface
22
{
23
    /**
24
     * @var TranslatorInterface
25
     */
26
    private $translator;
27
28
    /**
29
     * @var PermissionApiInterface
30
     */
31
    private $permissionApi;
32
33
    public function __construct(TranslatorInterface $translator, PermissionApiInterface $permissionApi)
34
    {
35
        $this->translator = $translator;
36
        $this->permissionApi = $permissionApi;
37
    }
38
39
    public function hasPermission(string $component, string $instance, string $level): bool
40
    {
41
        if (empty($component) || empty($instance) || empty($level)) {
42
            throw new InvalidArgumentException($this->translator->trans('Empty argument at') . ':' . __FILE__ . '::' . __LINE__);
43
        }
44
45
        return $this->permissionApi->hasPermission($component, $instance, constant($level));
46
    }
47
}
48