Console   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A onConsoleCommand() 0 6 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\Event\Listener;
10
11
use Gedmo\Translatable\TranslatableListener;
12
use Symfony\Component\Translation\TranslatorInterface;
13
14
class Console
15
{
16
    /**
17
     * @var string
18
     */
19
    const DEFAULT_LOCALE = 'en';
20
21
    /**
22
     * @var TranslatableListener
23
     */
24
    protected $translatable;
25
26
    /**
27
     * @var TranslatorInterface
28
     */
29
    protected $translator;
30
31
    /**
32
     * @var string
33
     */
34
    protected $locale;
35
36
    /**
37
     * @param TranslatableListener $translatable
38
     * @param TranslatorInterface $translator
39
     * @param string $locale
40
     */
41 3
    public function __construct(TranslatableListener $translatable, TranslatorInterface $translator, $locale = '')
42
    {
43 3
        $this->translatable = $translatable;
44 3
        $this->translator = $translator;
45 3
        $this->locale = $locale ?: self::DEFAULT_LOCALE;
46 3
    }
47
48 3
    public function onConsoleCommand()
49
    {
50 3
        setlocale(LC_ALL, $this->locale);
51 3
        $this->translator->setLocale($this->locale);
52 3
        $this->translatable->setTranslatableLocale(substr($this->locale, 0, 2));
53 3
    }
54
}
55