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

DefaultPathRuntime::getDefaultPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 11
rs 10
c 1
b 0
f 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 Symfony\Component\Routing\RouterInterface;
17
use Twig\Extension\RuntimeExtensionInterface;
18
use Zikula\ExtensionsModule\Api\ApiInterface\CapabilityApiInterface;
19
20
class DefaultPathRuntime implements RuntimeExtensionInterface
21
{
22
    /**
23
     * @var CapabilityApiInterface
24
     */
25
    private $capabilityApi;
26
27
    /**
28
     * @var RouterInterface
29
     */
30
    private $router;
31
32
    public function __construct(
33
        CapabilityApiInterface $capabilityApi,
34
        RouterInterface $router
35
    ) {
36
        $this->capabilityApi = $capabilityApi;
37
        $this->router = $router;
38
    }
39
40
    public function getDefaultPath(string $extensionName, $type = CapabilityApiInterface::USER): string
41
    {
42
        $capability = $this->capabilityApi->isCapable($extensionName, $type);
43
        if (!$capability) {
44
            return '';
45
        }
46
        if (isset($capability['route'])) {
47
            return $this->router->generate($capability['route']);
48
        }
49
50
        return '';
51
    }
52
}
53