Completed
Push — master ( f169c2...fc1f10 )
by Grégoire
12s
created

FakeTemplateRegistryExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 6 1
A getAdminTemplate() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
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 Sonata\AdminBundle\Tests\Twig\Extension;
15
16
use Twig\Extension\AbstractExtension;
17
use Twig\TwigFunction;
18
19
class FakeTemplateRegistryExtension extends AbstractExtension
20
{
21
    public function getFunctions()
22
    {
23
        return [
24
            new TwigFunction('get_admin_template', [$this, 'getAdminTemplate']),
25
        ];
26
    }
27
28
    public function getAdminTemplate($name, $adminCode)
29
    {
30
        $templates = [
31
            'base_list_field' => '@SonataAdmin/CRUD/base_list_field.html.twig',
32
        ];
33
34
        if (isset($templates[$name])) {
35
            return $templates[$name];
36
        }
37
38
        throw new \Exception(sprintf(
39
            'Template "%s" of Admin "%s" not found in FakeTemplateRegistry',
40
            $name,
41
            $adminCode
42
        ));
43
    }
44
}
45