ServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 79.31%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 23
cts 29
cp 0.7931
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerManager() 0 10 1
A registerLanguageChangeRoute() 0 15 2
A register() 0 6 1
A provides() 0 4 1
A boot() 0 6 1
1
<?php namespace Rocket\Translation\Support\Laravel5;
2
3
use Illuminate\Foundation\Application;
4
use Rocket\Translation\Commands\GenerateFiles;
5
6
class ServiceProvider extends \Illuminate\Support\ServiceProvider
7
{
8 216
    protected function registerManager()
9
    {
10 216
        $this->app->alias('i18n', \Rocket\Translation\I18NInterface::class);
11
        $this->app->singleton(
12 177
            'i18n',
13
            function (Application $app) {
14 216
                return $app->make(\Rocket\Translation\I18N::class);
15 216
            }
16
        );
17 216
    }
18
19 216
    protected function registerLanguageChangeRoute()
20 216
    {
21
        $this->app['router']->get(
22
            'lang/{lang}',
23
            function ($lang) {
24
                try {
25
                    $this->app['i18n']->setLanguageForSession($lang);
26
                } catch (\RuntimeException $e) {
27
                    $this->app['session']->flash('error', t('Cette langue n\'est pas disponible'));
28 216
                }
29 216
30
                return $this->app['redirect']->back();
31 216
            }
32
        );
33 216
    }
34 216
35 216
    /**
36 216
     * Register the service provider.
37
     *
38 216
     * @return void
39
     */
40 216
    public function register()
41 216
    {
42
        $this->registerManager();
43
44
        $this->registerLanguageChangeRoute();
45
    }
46
47
    /**
48 216
     * Get the services provided by the provider.
49
     *
50 216
     * @return array
51
     */
52 216
    public function provides()
53
    {
54 216
        return ['i18n'];
55 216
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function boot()
61
    {
62
        $this->loadMigrationsFrom(__DIR__.'/../../migrations');
63
64
        $this->commands([GenerateFiles::class]);
65
    }
66
}
67