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

ModVarRuntime   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 36
rs 10
c 1
b 0
f 1
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSystemVar() 0 7 2
A getModVar() 0 7 3
A __construct() 0 6 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\ExtensionsModule\Twig\Runtime;
15
16
use InvalidArgumentException;
17
use Symfony\Contracts\Translation\TranslatorInterface;
18
use Twig\Extension\RuntimeExtensionInterface;
19
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
20
21
class ModVarRuntime implements RuntimeExtensionInterface
22
{
23
    /**
24
     * @var TranslatorInterface
25
     */
26
    private $translator;
27
28
    /**
29
     * @var VariableApiInterface
30
     */
31
    private $variableApi;
32
33
    public function __construct(
34
        TranslatorInterface $translator,
35
        VariableApiInterface $variableApi
36
    ) {
37
        $this->translator = $translator;
38
        $this->variableApi = $variableApi;
39
    }
40
41
    public function getModVar(string $module, string $name, $default = null)
42
    {
43
        if (empty($module) || empty($name)) {
44
            throw new InvalidArgumentException($this->translator->trans('Empty argument at') . ':' . __FILE__ . '::' . __LINE__);
45
        }
46
47
        return $this->variableApi->get($module, $name, $default);
48
    }
49
50
    public function getSystemVar(string $name, $default = null)
51
    {
52
        if (empty($name)) {
53
            throw new InvalidArgumentException($this->translator->trans('Empty argument at') . ':' . __FILE__ . '::' . __LINE__);
54
        }
55
56
        return $this->variableApi->getSystemVar($name, $default);
57
    }
58
}
59