Passed
Push — master ( ab8dec...906584 )
by Julito
09:36
created

ChamiloExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 22
c 3
b 0
f 1
dl 0
loc 48
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 3 1
A __construct() 0 3 1
A getFilters() 0 18 1
A getIllustration() 0 3 1
A getName() 0 3 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Twig\Extension;
6
7
use Chamilo\CoreBundle\Entity\ResourceIllustrationInterface;
8
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
9
use Twig\Extension\AbstractExtension;
10
use Twig\TwigFilter;
11
12
/**
13
 * Class ChamiloExtension.
14
 */
15
class ChamiloExtension extends AbstractExtension
16
{
17
    private $illustrationRepository;
18
19
    public function __construct(IllustrationRepository $illustrationRepository)
20
    {
21
        $this->illustrationRepository = $illustrationRepository;
22
    }
23
24
    public function getFilters(): array
25
    {
26
        return [
27
            new TwigFilter('var_dump', 'var_dump'),
28
            new TwigFilter('icon', 'Display::get_icon_path'),
29
            new TwigFilter('get_lang', 'get_lang'),
30
            new TwigFilter('get_plugin_lang', 'get_plugin_lang'),
31
            new TwigFilter('icon', 'Display::get_icon_path'),
32
            new TwigFilter('img', 'Display::get_image'),
33
            new TwigFilter('api_get_local_time', 'api_get_local_time'),
34
            new TwigFilter('api_convert_and_format_date', 'api_convert_and_format_date'),
35
            new TwigFilter('format_date', 'api_format_date'),
36
            new TwigFilter('format_file_size', 'format_file_size'),
37
            new TwigFilter('date_to_time_ago', 'Display::dateToStringAgoAndLongDate'),
38
            new TwigFilter('api_get_configuration_value', 'api_get_configuration_value'),
39
            new TwigFilter('remove_xss', 'Security::remove_XSS'),
40
            new TwigFilter('format_user_full_name', 'UserManager::formatUserFullName'),
41
            new TwigFilter('illustration', [$this, 'getIllustration']),
42
        ];
43
    }
44
45
    public function getFunctions()
46
    {
47
        return [];
48
    }
49
50
    public function getIllustration(ResourceIllustrationInterface $resource): string
51
    {
52
        return $this->illustrationRepository->getIllustrationUrl($resource);
53
    }
54
55
    /**
56
     * Returns the name of the extension.
57
     *
58
     * @return string The extension name
59
     */
60
    public function getName()
61
    {
62
        return 'chamilo_extension';
63
    }
64
}
65