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

Extensions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A translator() 0 17 2
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
}