Completed
Push — master ( dd0acb...66994d )
by ARCANEDEV
05:42 queued 02:10
created

DeferredServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 79
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A provides() 0 8 1
A registerTransManager() 0 11 1
A registerTransChecker() 0 10 1
A registerLangPublisher() 0 10 1
1
<?php namespace Arcanedev\LaravelLang\Providers;
2
3
use Arcanedev\LaravelLang\{Contracts, TransChecker, TransManager, TransPublisher};
4
use Arcanedev\Support\Providers\ServiceProvider;
5
use Illuminate\Contracts\Support\DeferrableProvider;
6
use Illuminate\Foundation\Application;
7
8
/**
9
 * Class     DeferredServiceProvider
10
 *
11
 * @package  Arcanedev\LaravelLang\Providers
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class DeferredServiceProvider extends ServiceProvider implements DeferrableProvider
15
{
16
    /* -----------------------------------------------------------------
17
     |  Main Methods
18
     | -----------------------------------------------------------------
19
     */
20
21
    /**
22
     * Register any application services.
23
     */
24 54
    public function register(): void
25
    {
26 54
        $this->registerTransManager();
27 54
        $this->registerTransChecker();
28 54
        $this->registerLangPublisher();
29 54
    }
30
31
    /**
32
     * Get the services provided by the provider.
33
     *
34
     * @return array
35
     */
36 2
    public function provides(): array
37
    {
38
        return [
39 2
            Contracts\TransManager::class,
40
            Contracts\TransChecker::class,
41
            Contracts\TransPublisher::class,
42
        ];
43
    }
44
45
    /* -----------------------------------------------------------------
46
     |  Services
47
     | -----------------------------------------------------------------
48
     */
49
50
    /**
51
     * Register the trans manager.
52
     */
53 54
    private function registerTransManager()
54
    {
55
        $this->singleton(Contracts\TransManager::class, function (Application $app) {
56 40
            $paths = array_map('realpath', [
57 40
                'app'    => $app->langPath(),
58 40
                'vendor' => $app['config']->get('laravel-lang.vendor', ''),
59
            ]);
60
61 40
            return new TransManager($app['files'], $paths);
62 54
        });
63 54
    }
64
65
    /**
66
     * Register the trans checker.
67
     */
68 54
    private function registerTransChecker()
69
    {
70
        $this->singleton(Contracts\TransChecker::class, function (Application $app) {
71 12
            return new TransChecker(
72 12
                $app['translator'],
73 12
                $app[Contracts\TransManager::class],
74 12
                $app['config']->get('laravel-lang', [])
75
            );
76 54
        });
77 54
    }
78
79
    /**
80
     * Register the lang publisher.
81
     */
82 54
    private function registerLangPublisher()
83
    {
84
        $this->singleton(Contracts\TransPublisher::class, function (Application $app) {
85 24
            return new TransPublisher(
86 24
                $app['files'],
87 24
                $app[Contracts\TransManager::class],
88 24
                $app->langPath()
89
            );
90 54
        });
91 54
    }
92
}
93