AbstractHumanizerExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 33
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setTranslator() 0 4 1
1
<?php
2
3
namespace EmanueleMinotto\HumanizerBundle\Twig;
4
5
use Symfony\Component\Translation\Translator;
6
use Symfony\Component\Translation\TranslatorInterface;
7
use Twig_Extension;
8
9
/**
10
 * Abstract Twig extension used to map humanizer static methods to Twig filters.
11
 *
12
 * @author Emanuele Minotto <[email protected]>
13
 */
14
abstract class AbstractHumanizerExtension extends Twig_Extension
15
{
16
    /**
17
     * Default locale.
18
     *
19
     * @var string
20
     */
21
    const DEFAULT_LOCALE = 'en';
22
23
    /**
24
     * Locale value used by php-humanizer.
25
     *
26
     * @var TranslatorInterface
27
     */
28
    protected $translator;
29
30
    /**
31
     * Constructor with optional translator.
32
     *
33
     * @param TranslatorInterface|null $translator
34
     */
35 45
    public function __construct(TranslatorInterface $translator = null)
36
    {
37 45
        $this->setTranslator(
38 45
            $translator ?: new Translator(self::DEFAULT_LOCALE)
39 15
        );
40 45
    }
41
42 45
    public function setTranslator(TranslatorInterface $translator)
43
    {
44 45
        $this->translator = $translator;
45 45
    }
46
}
47