Passed
Push — master ( 58955b...e00fc3 )
by Ben
05:11
created

LocaleServiceProvider::getConfigValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Thinktomorrow\Locale;
4
5
use Illuminate\Support\ServiceProvider;
6
use Thinktomorrow\Locale\Parsers\RouteParser;
7
use Thinktomorrow\Locale\Parsers\UrlParser;
8
use Thinktomorrow\Locale\Values\Config;
9
10
class LocaleServiceProvider extends ServiceProvider
11
{
12 77
    public function register()
13
    {
14 77
        require_once __DIR__.'/helpers.php';
15
16 77
        $this->publishes([
17 77
            __DIR__.'/config/locale.php' => config_path('thinktomorrow/locale.php'),
18
        ]);
19
20 77
        $this->mergeConfigFrom(
21 77
            __DIR__.'/config/locale.php', 'thinktomorrow.locale'
22
        );
23
24 77
        $config = Config::from($this->getConfigValues());
25
26 77
        $this->app->singleton(Detect::class, function ($app) use($config) {
27
            return new Detect($app['request'], $config);
28 77
        });
29
30 77
        $this->app->singleton(UrlParser::class, function ($app) {
31 70
            return new UrlParser(
32 70
                $app['Illuminate\Contracts\Routing\UrlGenerator']
33
            );
34 77
        });
35
36 77
        $this->app->singleton(RouteParser::class, function ($app) {
37 70
            return new RouteParser(
38 70
                $app['Thinktomorrow\Locale\Parsers\UrlParser'],
39 70
                $app['translator']
40
            );
41 77
        });
42
43 77
        $this->app->singleton(LocaleUrl::class, function ($app) use($config) {
44
            return new LocaleUrl(
45
                $app['Thinktomorrow\Locale\Detect'],
46
                $app['Thinktomorrow\Locale\Parsers\UrlParser'],
47
                $app['Thinktomorrow\Locale\Parsers\RouteParser'],
48
                $config
49
            );
50 77
        });
51
52
        /*
53
         * Facade for getting current active scope
54
         */
55 77
        $this->app->singleton('tt-locale-scope', function ($app) {
56 10
            return $app->make(Detect::class)->detectLocale()->getScope();
57 77
        });
58 77
    }
59
60 77
    private function getConfigValues()
61
    {
62 77
        if (file_exists(config_path('thinktomorrow/locale.php'))) {
63
            return require config_path('thinktomorrow/locale.php');
64
        }
65
66 77
        return require __DIR__.'/config/locale.php';
67
    }
68
}
69