AbstractHumanizerExtension::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 1
nop 1
crap 2
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