Passed
Push — master ( d769b5...44239a )
by Mehmet
02:45
created

Extensions::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SelamiApp\Extension\Twig;
5
6
use Twig\Environment;
7
8
class Extensions
9
{
10
11
    private $twig;
12
13
    public function __construct(Environment $twig)
14
    {
15
        $this->twig = $twig;
16
    }
17
18
    public function translator(array $dictionary) : void
19
    {
20
21
        $filter = new \Twig_SimpleFunction(
22
            'translate',
23
            function (
24
                $string
25
            ) use ($dictionary) {
26
                if (array_key_exists($string, $dictionary)) {
27
                    return $dictionary[$string];
28
                }
29
                return $string;
30
            },
31
            array('is_safe' => array('html'))
32
        );
33
        $this->twig->addFunction($filter);
34
    }
35
}