Passed
Push — master ( 868a85...47fe80 )
by Morten Poul
03:20
created

TranslatorServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 17
c 4
b 0
f 1
dl 0
loc 57
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 3 1
A publishConfigs() 0 5 1
A register() 0 4 1
A publishMigrations() 0 11 2
A boot() 0 8 2
1
<?php
2
3
namespace Signifly\Translator;
4
5
use Illuminate\Support\ServiceProvider;
6
use Signifly\Translator\Contracts\Translator as TranslatorContract;
7
8
class TranslatorServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        if ($this->app->runningInConsole()) {
18
            $this->publishConfigs();
19
            $this->publishMigrations();
20
        }
21
22
        $this->mergeConfigFrom(__DIR__.'/../config/translator.php', 'translator');
23
    }
24
25
    /**
26
     * Register the service provider.
27
     *
28
     * @return void
29
     */
30
    public function register()
31
    {
32
        $this->app->singleton(TranslatorContract::class, function ($app) {
33
            return new Translator($app['config']);
34
        });
35
    }
36
37
    /**
38
     * Get the services provided by the provider.
39
     *
40
     * @return array
41
     */
42
    public function provides()
43
    {
44
        return [TranslatorContract::class];
45
    }
46
47
    protected function publishConfigs(): void
48
    {
49
        $this->publishes([
50
            __DIR__.'/../config/translator.php' => config_path('translator.php'),
51
        ], 'translator-config');
52
    }
53
54
    protected function publishMigrations(): void
55
    {
56
        if (class_exists('CreateTranslationsTable')) {
57
            return;
58
        }
59
60
        $timestamp = date('Y_m_d_His', time());
61
62
        $this->publishes([
63
            __DIR__.'/../migrations/create_translations_table.php.stub' => database_path("/migrations/{$timestamp}_create_translations_table.php"),
64
        ], 'translator-migrations');
65
    }
66
}
67